BenyD07
Posts: 4
Joined: Thu Apr 06, 2017 10:39 pm

Reading Voltage from a battery

Thu Apr 06, 2017 10:44 pm

I am currently using my Raspberry Pi as a data logger for a rain gauge. Essentially, a sensor is connected to the Raspberry Pi, measures and logs the data. I am using battery power, through the USB or microUSB port, to power the Pi. Is there a way to measure the voltage coming out of my battery ? Does the RPI have the capability of tracking its inputted voltage ?

Thanks for the help

Ben

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: Reading Voltage from a battery

Thu Apr 06, 2017 11:05 pm

An unaided RPi is unable to measure (to the sort of accuracy I imagine you seek) anything as its inputs are essentially 'yes/no' types. You need an Analogue to Digital Converter. See eg https://learn.adafruit.com/raspberry-pi ... rs/mcp3008 though there are many, many other possibilities. Note that if operating that chip from 3.3 volts (to make its interface compatible with a RPi) you might need to scale down the battery voltage (with a resistive divider) before applying it to the ADC input.

However I question your motive. There is no 'naked' battery that is suitable for directly powering a RPi. You always need a regulator or converter between the battery and the RPi. (USB power banks already incorporate that.) So the input to the micro-USB socket on a RPi should be remarkably constant and almost useless as an indication of remaining run time. Only if you have access to the actual battery terminals can you measure its voltage.

BenyD07
Posts: 4
Joined: Thu Apr 06, 2017 10:39 pm

Re: Reading Voltage from a battery

Fri Apr 07, 2017 3:07 pm

Thank you for the answer, very helpful. To clarify, what is of interest to me is tracking the voltage levels of the battery and not what is actually consumed by the device. I am exploring the possibility of either powering through a battery or a battery pack. Is there another parameter I can measure to anticipate when the Pi will shut down because of lack of power ?

Ben

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: Reading Voltage from a battery

Fri Apr 07, 2017 5:44 pm

As I already tried to explain:

The RPi will shut down when its input voltage gets too low. There is some circuitry between the battery itself and the 5 volt input to the RPi. The characteristics of the battery AND the characteristics of that circuitry both determine when the critical point is reached. You haven't said anything about either of those items. And don't interpret that as meaning that if you do I'll respond with a solution. :(

Return to “Advanced users”