Page 1 of 1

Reading Battery Information

Posted: Sun Aug 30, 2015 12:47 pm
by JonnyAlpha
Hi;

For my web controlled robot how do I read the battery information from my Pi.
I want to display this information on a web page?

Thanks

Re: Reading Battery Information

Posted: Sun Aug 30, 2015 1:37 pm
by mahjongg
which battery? the question cannot be answered in a precise way, as you don't provide information to base an answer on.
generally the state of a battery can be read by measuring its output voltage, for a lithium-ion battery, a fully charget battery will be something like 3.7V, which will sink towards 3.0V, but must not reach that value, or you will damage the battery.
a battery charger/monitor should take care of that, but will generally not give status about how full or empty the battery is.

a PI doesn't have any hardware to measure voltage with, for that you need to add an A/D converter chip, on the I2C or SPI bus.

Re: Reading Battery Information

Posted: Sun Aug 30, 2015 2:12 pm
by JonnyAlpha
Ah yes I posted a similar question on the Arduino Forum to monitor the battery supply to the Arduino and then thought about it a bit more and realised that the Arduino would only ever read 5v voltage it was being supplied from the 5v regulated supply provided by the L298N Motor Driver board.

On the Pi side the Pi is being powered by a 10000mAh USB power pack which provides 5v at 1.5 or 2.1A depending on which connection is used.

Re: Reading Battery Information

Posted: Sun Aug 30, 2015 4:47 pm
by JimmyN
JonnyAlpha wrote:Ah yes I posted a similar question on the Arduino Forum to monitor the battery supply to the Arduino and then thought about it a bit more and realised that the Arduino would only ever read 5v voltage it was being supplied from the 5v regulated supply provided by the L298N Motor Driver board.
That's correct, you have to measure the battery voltage before the regulator, since the voltage after the regulator will always be the same. Since you're using a 10Ah battery I'll assume it's LiPO. For radio control use we typically refer to a chart like this to determine remaining capacity after a run. The percentages are approximate but close enough.

Code: Select all

 100% 4.2V
  90  4.13V
  80  4.06V
  70  3.99V
  60  3.92V
  50  3.85V
  40  3.78V
  30  3.71V
  20  3.64V
  10  3.57V 
Fully charged will be 4.2V and it will be considered depleted at 3.3~3.4V. You'll get better longevity if you don't go below that, or store it for periods of time fully charged. The best storage voltage is around 3.7~3.8.

Another thing to consider when monitoring remaining capacity is the load. Unlike other batteries lithium cell resting voltage is a good indicator of charge remaining. A NiCad or NiMH laying on your desk will read ~1.2V whether it's 80% charged or 30%, after a rest period they always return to their "nominal" voltage. But a Li-ion (LiPo) resting voltage will vary according to charge level.

Say for instance you wanted to monitor remaining capacity of a 40C 10Ah LiPo, which is theoretically capable of a 400A burst due to the low internal resistance. If you're drawing a continuous 40A~50A out of it the voltage will slump some, so it would need to rest for a minute or two in order to get an accurate reading of the remaining capacity. But LiPo's have such low internal resistance that a 2A~4A load on a 40C 10Ah pack wouldn't pull the voltage down very much at all, so you could get a pretty accurate reading while it was under load.

If you have a fairly constant load, like powering a RPi, you could work out how the loaded voltage corresponds to the resting voltage and use those values to determine capacity remaining. With radio control however the load varies a lot, you might be drawing 50A one minute, then only 5A the next, so the only way to get a reasonable value is to let the cells rest for a couple minutes before measuring the voltage.