User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

PiCheckVoltage : monitor battery voltage

Postby aboudou » Fri Apr 26, 2013 9:44 am

Hi all,

I've made a small project intended to provide a mean to check battery voltage from Raspberry Pi, and run scripts when some voltage levels are reached (no battery plugged, dangerously low, low battery voltage and good battery voltage).

It could be used to avoid emptying too much batteries when their are used to power motors or other electric / electronic assemblies, or safely shutdown Raspberry Pi when voltage becomes to low.

The code and schematics are available here : https://github.com/aboudou/picheckvoltage

I hope it may be useful to somebody other than me :-)
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
User avatar
eried
Posts: 89
Joined: Mon Apr 15, 2013 2:11 am
Location: Chile

Re: PiCheckVoltage : monitor battery voltage

Postby eried » Fri Apr 26, 2013 8:15 pm

Cool stuff, how many hours you get from these batteries with the pi idle?

It seems a little complex just to check the batteries anyway :D but it is good to learn stuff. I think for an easier solution you can use http://www.ebay.com/itm/NEW-7-4V-11-1V- ... 460d6581d1 one of these and wire the warning led to 1 pin in the arduino (or the digital version of that one for up to 8 cells and configurable alarm)
My website: www.ried.cl
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Fri Apr 26, 2013 8:25 pm

I didn't tried yet a full charge with Pi plugged to the battery. I'm testing now with one of my robotic assembly (idle mode, only things powered are : MCP3008, voltage regulator, and MCP23008 + LD293D, not the motors) : with eight NiMH 2000 mAh, batteries are now 68% full and were plugged 23 hours ago.

When they'are depleted, I'll charge then again and run my Pi on it (web server, two apt-get update / dist-upgrade a day, WIFI USB stick).
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Sun Apr 28, 2013 11:25 am

I've just finished tests of battery life. With eight 2200 NiMH batteries, I can get :
  • 41 hours powering my idle robotic assembly, without Raspberry Pi
  • 3 hours powering my idle robotic assembly, with Rasberry Pi

Raspberry Pi was connected to network via Ethernet, as I just fried my WIFI adapter :roll:
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
grit
Posts: 12
Joined: Thu Jul 05, 2012 5:35 am
Location: Amsterdam
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby grit » Wed Feb 26, 2014 4:36 pm

Sorry for replying soooo late to this post, but I thought to mention that I'm using a LM3914 to measure the battery on the pi, using the LED output pins to trigger the appropriate GPIO port. I'm using a 12V battery though, not sure it this thing runs on 5V..
User avatar
wellsm89
Posts: 15
Joined: Wed Jan 23, 2013 9:40 am
Location: United Kingdom

Re: PiCheckVoltage : monitor battery voltage

Postby wellsm89 » Tue Apr 01, 2014 2:40 pm

Sorry for replying soooo late to this post, but I thought to mention that I'm using a LM3914 to measure the battery on the pi, using the LED output pins to trigger the appropriate GPIO port. I'm using a 12V battery though, not sure it this thing runs on 5V..


I am looking at using the LM3914 for monitoring my battery level, a 22.2V LiPo. Just wondering though did you straight from the output of the LM3914 to the GPIO pins? That will save me using led's and transistors.

Image
dramatix92
Posts: 5
Joined: Sat Apr 12, 2014 12:06 am

Re: PiCheckVoltage : monitor battery voltage

Postby dramatix92 » Wed Apr 16, 2014 5:38 am

Is it necessary to have a SIGFOX module connected for the PiCheckVoltage to work.
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Wed Apr 16, 2014 5:43 am

Absolutely not. Sigfox use is disabled by default (see config.py file)
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
dramatix92
Posts: 5
Joined: Sat Apr 12, 2014 12:06 am

Re: PiCheckVoltage : monitor battery voltage

Postby dramatix92 » Wed Apr 16, 2014 4:46 pm

Sweet! That means I don't need any sort of internet connection for this, right?
I'm currently working on a project for school using the Raspberry Pi, and I need to monitor the level by percentage. I know in your configuration, you used 8 Lithium Ion batteries. I'm planning to use this:

http://www.amazon.com/OXA-10000mAh-Port ... B00FVS2AXQ

Please forgive me as I'm fairly basic with Java code and circuitry. I was planning to cut the wire, and connect it to a breadboard. From there, I was going to connect it to a cut micro B USB cable. Will I be able to monitor the voltage with this battery and PiCheckVoltage?
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Wed Apr 16, 2014 5:49 pm

dramatix92 wrote:Sweet! That means I don't need any sort of internet connection for this, right?


No, I can be use purely in offline mode.

dramatix92 wrote:http://www.amazon.com/OXA-10000mAh-Portable-External-Battery/dp/B00FVS2AXQ/ref=sr_1_1?s=electronics&ie=UTF8&qid=1396860841&sr=1-1&keywords=B00FVS2AXQ

Please forgive me as I'm fairly basic with Java code and circuitry. I was planning to cut the wire, and connect it to a breadboard. From there, I was going to connect it to a cut micro B USB cable. Will I be able to monitor the voltage with this battery and PiCheckVoltage?


With USB power banks, you'll only get 5V ±5%, except when the battery is empty, where you get 0V :-), So my code won't be useful (a.k.a you won't know when the battery is drained).
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
dramatix92
Posts: 5
Joined: Sat Apr 12, 2014 12:06 am

Re: PiCheckVoltage : monitor battery voltage

Postby dramatix92 » Wed Apr 23, 2014 2:47 am

Alright, I'll look into getting some NiMH batteries. But why did you step the voltage down to 3.14V? Is it necessary to do that?
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Wed Apr 23, 2014 5:21 am

dramatix92 wrote:Alright, I'll look into getting some NiMH batteries. But why did you step the voltage down to 3.14V? Is it necessary to do that?


With MCP3008, the max voltage you can measure is equal to its VIN voltage, and the voltage used through its SPI pins is equals to its VIN voltage too.

As Raspberry Pi GPIO pins are 3.3V only, you have to power MCP3008 with 3.3V, then use a voltage divider to step down measured voltage to maximum 3.3V

The voltage divider I used steps maximum NiMH pack voltage (11.2V) to 3.14V because of chosen resistors' values.
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
dramatix92
Posts: 5
Joined: Sat Apr 12, 2014 12:06 am

Re: PiCheckVoltage : monitor battery voltage

Postby dramatix92 » Wed Apr 23, 2014 5:33 am

Couldn't you use the 5V pin instead?
User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact:

Re: PiCheckVoltage : monitor battery voltage

Postby aboudou » Wed Apr 23, 2014 9:15 am

dramatix92 wrote:Couldn't you use the 5V pin instead?


5V to power MCP3008 ? Then it will try to communicate with the RasPi on SPI pins with a 5V logic, destroying the RasPi pins (or you'll have to put a level shifter between RasPi and MCP3008. And if you do that, you'll still have to use a voltage divider to step NiMH pack max voltage to 5V max.

Remember :
- MCP3008 analog pin max voltage = MCP3008 VIN pin voltage (i.e. VIN = 3.3V means analog in 3.3V max)
- MCP3008 SPI pins voltage = MCP3008 VIN pin voltage (i.e. VIN = 5V means SPI pins at 5V)
- RaspPi max voltage on GPIO pins = 3.3V
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
Lamirand
Posts: 1
Joined: Thu Jan 19, 2017 3:58 pm

Re: PiCheckVoltage : monitor battery voltage

Postby Lamirand » Thu Jan 19, 2017 4:11 pm

Good day

http://www.lediouris.net/RaspberryPI/AD ... r-12v.html

I offer this link which might be helpful to some of you.

Here is what I'm trying to do and why that link is helping.

use my RasPi to monitor RV coach batteries (12volt marine batteries) and send me an email if batteries drop below a certain level.

the RasPi will be powered by the 12v batteries in the RV.
If the solar panal on the RV roof doesn't keep the batteries charged above, say 12 volts (which will happen in the summer when I park it under a rain canopy for a week or so between camping trips) then I will get an email if the trailer camper is in my driveway and thus within wifi range, (or if it is at some location where I have signed into the wifi). Actually the scripts and work done by the gentleman at www.lediouris.net means I'll get a daily email reporting battery level.

I am now buying an ADC, pentiometer, and cobbler to get started.

possible addition:

it might be good to use the RasPi's Bluetooth to send updates directly to my phone as a reminder to check or alert to low battery if we are in a camp ground without wifi.

I am interested in anyone's help or questions. I am just beginning on this and must learn some Java programming to proceed.

rod