red6
Posts: 61
Joined: Thu Sep 20, 2012 12:32 am
Location: Toronto, Canada

Simple A to D to monitor voltage

Sun Oct 28, 2012 6:23 am

My RaspBerry Pi is powered by solar. Yup, it cost more than the Pi. But the Pi has way more utility.

How do I monitor the voltage on the battery that sits behind the solar panel and charge controller?

I see someone else is doing it nicely and pumping out real time graphs but he/she does not explain how they monitor the voltage other than to say that they have an Arduino dedicated to that job.
There muset be a simple circuit that I can add to my breadboard that currently has a Cobbler, Level Converter, buttons, and LEDs. But I just don't know how to design a voltage sensor other than I know that I need some sort of ADC chip.

Any thoughts from the experts?

Thanks.

Mark

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 9:07 am

Here's a blog post that might help. Not mine, but it might help.

http://www.raspberrypi-spy.co.uk/2012/0 ... -gpio-pin/
There are 10 types of people in this world. Those that understand binary, and those that don't.

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 1:52 pm

I was actually going to give that simulated analog reading a try this week.

I am in the same boat as you red6, I plan on monitoring current and voltage on a 12V solar generator.

I have about the same level of knowledge as you do too, so please take my notes below for that, one newb to another newb and make sure to confirm anything I mention pls.

You are right, normally we would need an analog to digital converter because the RPi does not have that built in. The Arduino does have that built in so that takes one bit out if you use an arduino, but I really want to use the RPi because the Arduino is just a bit more limited in other ways.

Or, we can look at doing something like the above mentioned thread, where we simulate an ADC (Analog Digital Converter).

But ADC chips are cheap really, just a few dollars, I just never could find the right one as I am not very skilled in working with integrated circuit (IC) chips or specifying them. I also do no fully understand what comes out of the other side of an ADC. 0v - 5v or 0v - 3.3v goes in one side, and I think a number comes out the other side of the ADC with the Arduino I think it was 0-254, or 0-1024.

But for voltage, we will first have to build a simple circuit called a 'voltage divider' to get the battery voltage (mine is nominal 12v) down to a voltage the RPi (or ADC) can handle.

That is the part I haven't investigated yet, but when I was doing it on the Arduino, I had to get it so the voltage off the battery was never more than 5v as the Arduino is a 5v based so its ADC pins take 5v or less. So for a 12v system which can really be up to 15v or 16v I think I would have to divide the voltage by 4. Then you just have to calibrate it. 12v / 4 = 3v so 3v on my ADC would mean the battery was at 12 v. 4v on my ADC would mean the battery was at 16v.

Measuring current, which you did not mention is a whole other issue, more complicated, but I think I have that worked out with a Hall Effect sensor.

Hope that helps some.

DJJo14
Posts: 4
Joined: Mon Oct 22, 2012 11:01 am

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 4:35 pm

Look in to a i2c adc. I googleed it an found http://www.briandorey.com/post/Raspberr ... erter.aspx

red6
Posts: 61
Joined: Thu Sep 20, 2012 12:32 am
Location: Toronto, Canada

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 4:44 pm

Thanks for the tips folks. Everything you said makes sense and the link at raspberrypi-spy.co.uk is helpful too.

No to figure out what resistors and capacitors are needed and if I need the ability to disconnect the 12 volt lead from the battery so that I can connect and then measure the duration. My first thought is to use a small relay.

Measuring current would be nice too.

red6
Posts: 61
Joined: Thu Sep 20, 2012 12:32 am
Location: Toronto, Canada

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 4:47 pm

DJJo14 wrote:Look in to a i2c adc. I googleed it an found http://www.briandorey.com/post/Raspberr ... erter.aspx
It looks like that would do the job but I was hoping to keep it simple (mainly because I don't understand all the stuff that is going on inside of Brian's board).

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 4:59 pm

I just bought one of those ADC boards from ABElectronics last week, but I haven't had a chance to use it yet as I am still in the process of getting myself up to speed on GPIO pins in general.

Again, if I was better at finding the right IC I could probably have come up with something less expensive, but that looked great to me for a ready made solution.

Double check this: I am under the impression that I can just run two leads off of my battery to my voltage divider while the battery is in use. Small gauge wire should be fine as no real current will be going over it.

As to measuring the current flow I used the 20amp version of these:
http://www.devicecraft.com/sihaefbicuse.html

Which were perfect for my Arduino because they put out 2.5v at 0 amps and then went up to 5v at 20 amps in one direction and down to 0v at 20 amps in the other direction. They ship overseas for cheap and the sensors got here fast.

You can see the hall effect sensors installed here:
http://occupythesun.org/index.php?title ... G_2627.JPG

The nice part is they are outside of the current flow so you never have to worry about current and your sensor set up.
Last edited by bgirardot on Sun Oct 28, 2012 5:07 pm, edited 1 time in total.

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 5:05 pm

Funny while we were talking about this someone posted a question about a specific ADC chip here:
http://www.raspberrypi.org/phpBB3/viewt ... 44&t=21328

That is a good example of just a bare IC that does ADC, so you would need to put that into a circuit to use it and interface it with the RPi.

Here is the actual chip they were asking about:
http://www.hobbytronics.co.uk/adc-i2c-slave

red6
Posts: 61
Joined: Thu Sep 20, 2012 12:32 am
Location: Toronto, Canada

Re: Simple A to D to monitor voltage

Sun Oct 28, 2012 5:41 pm

bgirardot wrote:Funny while we were talking about this someone posted a question about a specific ADC chip here:
http://www.raspberrypi.org/phpBB3/viewt ... 44&t=21328

That is a good example of just a bare IC that does ADC, so you would need to put that into a circuit to use it and interface it with the RPi.

Here is the actual chip they were asking about:
http://www.hobbytronics.co.uk/adc-i2c-slave
That chip looks like it could be part of the recipe.

munklefish
Posts: 88
Joined: Tue Oct 02, 2012 5:35 pm
Location: Neumarkt in der Oberpfalz
Contact: Website

Re: Simple A to D to monitor voltage

Sun Nov 11, 2012 11:50 pm

Any progress updates on this???

Id really like to do this, but as of yet have next to no idea how.

Thanks.
http://www.codeclinic.de

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Mon Nov 12, 2012 12:48 am

I am using the abelectronics adc board and so far it works fine for the voltage monitoring on my battery and the voltage generated by my solar panel.

The voltage divider part was not exactly straight forward for me with the adc board but someone from ab electronics did answer my question about getting it working and it does work now as far as I can tell, I haven't run it more than a few hours but I assume it will continue to run just fine.

Here is the thread about that:
http://www.raspberrypi.org/phpBB3/viewt ... 44&t=22330

The short version is my voltage divider circuit was fine, but when coupled with the resistors built into the adc board, the voltage was divided too much so you have to take the two resistors on the adc board itself into account, but it did essentially come down to what the ab electronics person said, just stick a 33kOhm resistor in there and you are good with the battery. For the solar panel I used a 47KOhm resistor as the panels produce a higher voltage than the battery.

I haven't had a chance to test the hall effect sensors for current monitoring with the adc board yet, hopefully next week.
Last edited by bgirardot on Sun May 12, 2013 11:26 am, edited 1 time in total.

caldimerda
Posts: 69
Joined: Tue Oct 09, 2012 9:41 am

Re: Simple A to D to monitor voltage

Thu Nov 15, 2012 10:09 am

You could try using a DS2438. It's a 1-wire device - there are quite a few of us using similar ICs for temperature monitoring. There is a little how-to at the manufacturer's website: http://www.maximintegrated.com/app-note ... mvp/id/125

And there's a chap who has taken it a step further to monitor his Raspi's power usage: http://www.lancs.ac.uk/pg/elliotj3/Dissertation.pdf. I imagine he's on this forum somewhere.

I've ordered the parts to give this a try - it looks like a cheap way to monitor a solar system that feeds a lead acid battery.

karlos13
Posts: 13
Joined: Wed May 01, 2013 3:36 am

Re: Simple A to D to monitor voltage

Sun May 12, 2013 9:45 am

I too wish to monitor the solar voltage (12 volt panels) with the Pi and display it on a munin graph and eventually add other gpio devices as I learn more, but I'm a little confused. :ugeek:

From my readings the hall sensor looks like the simplest solution with a arduino...
http://occupythesun.org/index.php?title ... G_2627.JPG

But what is the simplest solution for an IC board novice with the Pi?

Is this converter the only way, I guess adding another sensor ?
http://www.briandorey.com/post/Raspberr ... erter.aspx

rownyr
Posts: 41
Joined: Wed Jul 11, 2012 1:25 am

Re: Simple A to D to monitor voltage

Sun May 12, 2013 11:19 am

I'm using MCP3208 chip, it works fine with 3.3V power and ref voltage. But if you want the 12V range you should use voltage divider to 3.3V (use large resistance resistors).

User avatar
TimG
Posts: 300
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Sun May 12, 2013 5:17 pm

I think an Arduino is the easiest thing to use here. It has a 10-bit ADC, 6 analogue channels, is easy to program, and there are a number of ways to connect it to the Raspberry Pi.

A standard Arduino Uno can be connected via USB. Alternatively an Arduino Pro or Pro-Mini (3.3V 8MHz version) is cheaper, smaller, and can be connected to the GPIO pins (via I2C, SPI, or ordinary serial).

karlos13
Posts: 13
Joined: Wed May 01, 2013 3:36 am

Re: Simple A to D to monitor voltage

Sun May 12, 2013 11:18 pm

Thanks Guys, I do have an arduino so I could use it, but I still need to add the hall sensors and a voltage divider and I gather that IC work would be needed.

Yes I'm a electronics noob.

So I guess this is the path:
  • Connect the hall sensor to an IC (?) of some sort
    IC connects to the Arduino.
    current is interpreted by the Arduino script and
    Arduino is connected to the Pi via USB or is gpio simpler(?)
    The Pi reads the results
Am I way off here? :shock:

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13223
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Simple A to D to monitor voltage

Sun May 12, 2013 11:55 pm

Depends on the hall sensor!

Because you do not give any information about it its impossible to guess how to interface it.

Also, yes the PI isn't a microcontroller like the Arduino, so for starters it doesn't have -any- analog inputs. That may sound as an important omission, but actually its quite simple to add A/D converters to your hearts delight. There are many solutions, from a very simple (old) ADC0804 (not a good choice as its a 5V device, but its still possible) to somewhat more modern I2C device, upto very fast SPI ADC converters, or even I2S audio codexes. In all cases you should consider that the PI uses 3V3 levels, to 5V levels.
Using an arduino (or rather the ATmega micro controller) for I/O expansion (including analog I/O) is possible, but again interfacing them should be done with 3V3 levels. Which is exactly what the Atmega on a Gertboard does. For many things its an overkill though.

One example to show that such a solution might not be necessary at all, is that monitoring a slowly varying voltage (or resistor) is actually doable without any extra hardware, except for a small capacitor! A small current, running through a (variable) resistor from a (variable) voltage source will slowly charge a capacitor, a PI can detect when that voltage crosses a threshold, then discharge the capacitor and test how long it takes for the capacitor to charge to the threshold voltage again. The amount of time it takes is proportional to the variable resistance and/or voltage. So this can be used a simple means to detect variable voltages or resistances. several threads can be found in this forum about such a simple way to monitor voltages, or light dependent resistors, or potentiometers and such.

User avatar
TimG
Posts: 300
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Mon May 13, 2013 12:00 am

karlos13 wrote: So I guess this is the path:
That's about right. Whether you need any extra circuitry depends on the sensors you're using. The Arduino can only read voltages between 0V and the supply (usually 5V or 3.3V), so to measure the voltage from 12V solar panels you need a voltage divider (which is just a pair of resistors).

Some hall sensors come with an integrated amplifier, in which case you can probably connect it directly to the Arduino. Otherwise you'll need some kind of signal amplifier.

Assuming you have an Arduino Uno, I'd suggest going with a USB connection to start with. It's slightly easier to hook up and debug.

BTW to get you going with the Arduino side of things there's plenty of high-quality information available. Some of the kits, such as this one, are really excellent and cover both programming and electronics. There are also a lot of helpful people on the Arduino forums.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13223
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Simple A to D to monitor voltage

Mon May 13, 2013 12:15 am

Adding a quality ADC to a PI is a much simpler solution than trying to add an arduino (of any sort) to the PI, If you think you are not up to it, then think again! the firm adafruit has simple solutions, for example this one that uses an eight channel 10-bit ADC connected via the high-speed SPI bus directly to a PI, with a tutorial.
http://www.raspberrypi-webshop.nl/a-289 ... interface/

User avatar
TimG
Posts: 300
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Mon May 13, 2013 12:19 am

PS. What kind of currents are you planning to measure? Are they also at 12V? I'm not sure hall sensors are the easiest solution. Here's a couple of links which might be useful:
http://www.vwlowen.co.uk/arduino/current/current.htm
http://openenergymonitor.org/emon/build ... rrent-only

karlos13
Posts: 13
Joined: Wed May 01, 2013 3:36 am

Re: Simple A to D to monitor voltage

Mon May 13, 2013 1:21 am

mahjongg wrote:Adding a quality ADC to a PI is a much simpler solution
Thanks for the links and adafruit looks good. Awesome help thanks all.
Tim wrote:What kind of currents are you planning to measure? Are they also at 12V?
12 volt only, from the solar panel and the battery... I mentioned the hall sensors as they were attached inline to the solar regulator in the pic I linked earlier. That looked like the perfect way to do it.

So lets forget about the Arduino for the meantime. This MCP3008 ADC chip can be used as per the tutorial here http://learn.adafruit.com/send-raspberr ... ta-to-cosm. Adafruit also have the INA219 High Side DC Current Sensor, http://www.adafruit.com/products/904 which looks perfect.

I assume this sensor can then be connected onto this breadboard
Image here.

Is anything else needed ?

User avatar
TimG
Posts: 300
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Mon May 13, 2013 7:13 am

mahjongg wrote:Adding a quality ADC to a PI is a much simpler solution than trying to add an arduino
Well, I'm not sure about that. For someone new to electronics a single USB cable might be easier than messing with the electrically-fragile GPIO connections on the RPi.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13223
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Simple A to D to monitor voltage

Mon May 13, 2013 8:36 am

Not any more fragile than those of an Arduino, yes they are 3V3 not 5V as the SoC runs on 3V3 not 5V, but thats not really different from an Arduino, you cannot directly tie a 12V signal to an arduino GPIO pin either, for exactly the same reason as on a PI. Saying the GPIO of a PI are "fragile" is a red herring. If you must connect a hard 5V signal to a GPIO of a PI, actually all you need to add is a 1K resistor, or if you want to do it fancy you use two resistors as a voltage divider.

Why hassle with two distinct systems if using one is perfectly possible.

Using an ATmega chip (the heart of an Arduino) running on 3V3 as an add-on connected to the UART of the PI is what you could use if you needed masses of extra (analog) or other I/O that requires strict timing demands, for most other causes the PI alone is perfectly capable on its own.

Also, the PI is designed to learn from, using USB is a technical hack which shouldn't be teached, its using the wrong tool for the job. Its the kind of mentality the raspberry PI foundation probably tries to discourage, not encourage. when you design a system you shouldn't add unnecessary complexity and cost just to make it easier for you. The Gertboard teaches you how to do this the proper way. connecting the SoC's and microcontrollers UART's directly together, running both chips with the same voltage levels.

User avatar
TimG
Posts: 300
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Simple A to D to monitor voltage

Mon May 13, 2013 8:37 am

karlos13 wrote:Adafruit also have the INA219 High Side DC Current Sensor, http://www.adafruit.com/products/904 which looks perfect.
That looks much better than the magnetic sensors. As long as you're within the 3.2A spec, I'd say it's ideal. It sounds like this board will even do the voltage measurement for you too.

karlos13
Posts: 13
Joined: Wed May 01, 2013 3:36 am

Re: Simple A to D to monitor voltage

Mon May 13, 2013 8:52 am

As long as you're within the 3.2A spec,
:o I didnt even see that limit, lol. And yes I'm within it, I shall order those parts and report back.

Return to “Advanced users”