How hardware.voltage() report low voltage if power supply always produces 3.3v?

Just wonder how to report low voltage or battery warning using hardware.voltage()? The thing I don’t understand is that if power supply always produces 3.3v or nothing, how do we know there is a low battery. So how to produce low battery warning?


I believe this intend for impee designs with direct battery power (e.g. Nora) and no regulator. So if your using April or Hanna hardware.voltage() is as you say no use. You can use an analog input to monitor the battery.

Correct; you may need to use a resistor divider (ideally with a FET in line so you can disable the leakage path) in order to get the voltage to a level which is acceptable by the imp (ie, between 0v and the imp supply voltage).

Thanks controlCloud and Hugo, I’m clear now.

Could you please tell us what the input impedance of the Imp pin if it is configured as an Analog input? I was wondering whether we can use high value resistor voltage divider to do the trick without draining the battery so fast by the voltage divider or the ADC leakage current (Or on the other hand, if the input impedance is too low to cause ADC error). If a FET need to be used, then not only a couple of more components needed, but an additional GPIO is needed to turn on/off the FET. Then two pins out of the 6 pins is consumed by the battery monitoring!



I was hoping an actual hardware engineer would chip in on the input impedance :wink: because the STM32 datasheet isn’t very clear. It says that the analogue input impedance is max 50K ohms, but then gives a formula that, for typical conditions, gives a value much much less – only a couple of K ohms.


The formula is rather complex, mainly due to the charge being taken from the line by the ADC for every conversion, however there’s also IO pin leakage as several IOs are muxed together with the line configured as analog input.

We’ve not had any issues using 100k-ish dividers in real life, though.