A Forum run by Enthusiasts of MidNite Solar

The Open Source software/hardware corner => Beagle Board => Topic started by: xsnrg on January 04, 2015, 11:13:21 PM

Title: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 04, 2015, 11:13:21 PM
I received a Beaglebone Black (BBB or just BB) for Christmas, so decided to put it to work.  In reading up on what it can do, I noticed that it has A to D ability with a range of 1.8vdc.  This range isn't good for much by itself, but with a voltage divider circuit comprised of two resistors, it makes a quite handy DVM.  Expand on this with the fact that it has multiple of these inputs, can run SNMPd, and pulls less than a watt doing it, and all of a sudden you have some real monitoring power.

Tonight I finished the first configuration of what I will call a simple pod.  This pod uses two resistors to split the voltage to feed the BBB.  I measured the resistance of each resistor (I chose 10k and 100k nominal), and found out the ratio to divide by (R1/(R1+R2)).  In my case, .09155.  With this setup, my voltage samples are well within the BBB's range for any value of a 12v nominal battery.  To monitor different voltages, simply set up the resistors so that the possible range on the input never exceeds the 1.8v the BB can use.  I plan on doing this in additional pods down the road.

Here are the steps, then I will go into detail if anyone wants to see what I did.

1) figure out resistors... use high values to not draw much of any current.
2) create the circuit with the resistors in series.  In my case, the voltage drop across the smaller resistor is what we want.
3) assemble the circuit, and test it a few times with a DVM and a couple small household batteries
4) attach the circuit to the Beaglebone
5) connect NiCd or similar low voltage battery and test again.  I say NiCd as it is 1.2v nominal incase something is fubar.  You should see values in the register on the BB
6) install and configure snmpd on the BB
7) set up cacti or your snmpd data logger/grapher of choice


details:

Step 1) to find a good value of resistors, consider the voltage you want to measure.  In my case, a 12v nominal battery may have a range of 10 (lets hope not) to 18v (again, ouch).  This means we want to reduce the input voltage into the BBB by an order of magnitude or slightly more.  This was an easy effort as 10k and 100k resistors are commonplace, and will reduce by a factor of about 11.  (R1/(R1+R2)).  In my case, R1 = 10.08k, and R2=100.0K, so the math gave me a factor of 0.09155.  We can argue about significant digits later  8)

Step 2) I used a breadboard and some gold tolerance resistors I had laying around.  Put the resistors in series.  I put the larger one first, and take measurements across the 10k.  I put a lead in for the battery +, a lead in between the resistors for AIN0, and two leads on the end of the second resistor for battery ground and DGND on the BBB

Step 3) Using my fluke, I tested not only the voltage across the smaller resistor, but also across my larger resistor, mostly to make sure my 25yr old breadboard was still operating well.  I also took readings for the batteries I used to test the circuit (1.2v, 1.5v, 9v, 18v).  Once I had all these logged, I was able to see the math was accurate and the readings were as expected with the factor taken into account.

Step 4) I chose to use AIN0 on P9 pin 39.  I also used pin 47 on P9 for the ground.  There are a few more steps to perform here.  For whatever reason, the module that allows you to use the AIN functionality is not loaded in the BBB.

To load the module and set it up, drop these lines in a script.  I called mine vsetup.sh.  I will later make it do this at boot.


echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
cat /sys/devices/ocp.3/helper.15/AIN0


set the script to executable and give it a run.  It should output a value, which is what the second line does to make sure things are working.

Step 5) This is where it gets fun!  test the setup by connecting various batteries.  Make sure you get the positive leads correct.  I used a 1.2 NiCd, a 1.5 alkaline, a 9v, and 2 connected 9v to make 18v.  With the battery connected, and the BB connected to the circuit, you can issue the command below and see results!  Don't forget that our scaling factor from step 1 is not yet applied. 


cat /sys/devices/ocp.3/helper.15/AIN0


Step 6)
apt-get update;apt-get install snmpd

edit the file at /etc/snmp/snmpd.conf, and add the line:
pass .1.3.6.1.4.1.2021.55.1 /usr/local/bin/getvolts.sh
then restart the snmpd service.

This is the content of /usr/local/bin/getvolts.sh:


#!/bin/sh
echo .1.3.6.1.4.1.2021.55.1
echo "integer"
echo "scale=0; `/bin/cat /sys/devices/ocp.3/helper.15/AIN0`/.09155" | bc


So, a little about getvolts.sh... I chose to use the "pass" functionality of net-snmp.  This allow you the most control over the what you do with snmp when we extend its functionality.  I won't go into details about MIBs and such.  If you want to know more about SNMP, feel free to ask, but for now we will assume a working knowledge.

Using "pass" we have to send everything manually.  There are three parts that snmp on the calling server is expecting, the OID that we are using to expand SNMP, the type, in our case we want to use integer, and the actual value.  The value is the fun part.  This is where we read the register, apply our divisor to bring us back to mV (remember, the resistors scaled the value), and use bc to do the math functions that the shell is not capable of directly.  The end result of the last line is a value in millivolts, which is great because that is what we want to pass through snmp-- integers. scale=0 comes in to make sure nothing is dangling behind the decimal.

Test it.

Running getvolts.sh directly should return 3 lines.  The first line is the SNMP OID.  The second line is the word "integer" and the 3rd line should be our prize in mV.  Save the file in /usr/local/bin, or anywhere that the snmpd daemon can read it.  On the BBB by default, snmpd runs as user snmp, so keep that in mind.

7) Harvest.  I like cacti, but I am getting old I know.  There are some fancy new things out there like graphina and the like.  Basically, use whatever you want.  If you have snmpd set up right on the BBB, you can get to your data from anywhere you want, using any software you want.  A test in my case looks like this:


snmpget -v2c -c <community> <IP or hostname of BBB> .1.3.6.1.4.1.2021.55.1


It should return an integer value in mV.  Rock on!  Create more pods.


Note that while this is cool and fun, I still await the data logger output for my KID :)

Jim

Note that the graph image attached included a lot of playing around, my voltages are not that crazy.  I should have it hooked up gathering real data shortly.


Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 09, 2015, 11:03:27 PM
Graph from part of today.  I didn't figure the battery discharge would be so linear.  Nice to see it over time.

Title: Re: Beaglebone black DVM pods and graphs
Post by: boB on January 11, 2015, 03:21:39 AM
Excess Energy, this is great stuff !!!

I really thing the BB is the way to go since the processor actually has real documentation (about 5000 pages worth !)

Looks really good, and useful !

Keep us posted !  I gotta get one of these too.  BTW, Radio Shack up here actually sells these boards, Raspberry Pi's
and Arduinos.

boB
Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 11, 2015, 10:48:30 AM
Thanks boB,  I am really enjoying the Beaglebone.  There is an amazing amount of stuff it can do with all the IO ability.

I really need Mario to open that serial port up though on my KID.  I know it is being worked on. As mentioned in another thread, I am a data junkie, and would probably have the entire SNMP MIB created for the data from the KID in very short order.  I'd probably even share it :)  Graphs for battery temp, system temp, FET temp, input voltage, input current, output current, battery SOC, etc... ah man, bring it.

(Hint Hint Nudge Nudge)

I was also thinking about the classic.  It has the TCP/IP stack native already, what does it use to expose the metrics?  I don't have one, so have not jumped in on learning it to that level.

Edit:  I was going to share this URL.  Last night I figured out how to pull data from the weather station so I could plot the W/m^2 plot at the same scale as the voltage in Cacti.  It is the start of my RE metrics page:  http://www.howardweb.org/weather/solar/index.html (http://www.howardweb.org/weather/solar/index.html)

Title: Re: Beaglebone black DVM pods and graphs
Post by: Westbranch on January 11, 2015, 01:01:06 PM
xsnrg, just took a look at the link,: suggestion just to clarify the Volts graph, that it is battery volts or ??  Volts, like at-Inverter?  that  one might be a useful one to see just exactly where your LVD kicks in at...

hth
Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 11, 2015, 01:34:23 PM
A good suggestion.  I changed the solar energy graph, but didn't change the voltage.  It has been updated.  Thanks for looking.
Title: Re: Beaglebone black DVM pods and graphs
Post by: Westbranch on January 11, 2015, 01:49:59 PM
I'm not sure what it means but the video box at the bottom of the page has a message

No Video with supported format and MME type found
  ?
Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 11, 2015, 02:09:11 PM
heh, a work in progress... trying to figure out html5 embedded video.  I have a cheap webcam pointed at the screen of my KID.

EDIT:  It does not look like HTML5 supports embedded mjpeg streams, just mp4.  The simple <video> tag may be a no-go.

EDIT2: Not as nice as I had hoped, but I found a Java applet that works once you accept prompts.  I was able to get it to work in FF, but not yet in Chrome.

EDIT3: Meh.  Plugin is painful looking for more options

EDIT4: Think I nailed it.  Embedded as a plain ole img tag and let the browser do what it will. 

It is working well on my internal network now, let me know if it works out there.  The camera is one I had laying around, so don't be too critical of the poor image quality  ;)
Title: Re: Beaglebone black DVM pods and graphs
Post by: boB on January 11, 2015, 05:32:58 PM
Quote from: xsnrg on January 11, 2015, 10:48:30 AM
Thanks boB,  I am really enjoying the Beaglebone.  There is an amazing amount of stuff it can do with all the IO ability.

I really need Mario to open that serial port up though on my KID.  I know it is being worked on. As mentioned in another thread, I am a data junkie, and would probably have the entire SNMP MIB created for the data from the KID in very short order.  I'd probably even share it :)  Graphs for battery temp, system temp, FET temp, input voltage, input current, output current, battery SOC, etc... ah man, bring it.

(Hint Hint Nudge Nudge)


(wink wink too !)

Mario was just talking with me about the document for his serial codes the other day so he is working on this.

Yes, there are some metrics for the Classic communications using modbus.  I will see if I can send you that info.

boB
Title: Re: Beaglebone black DVM pods and graphs
Post by: Westbranch on January 11, 2015, 06:52:58 PM
Video is readable...  got a bit of a what the??  when it refreshed I guess as everything 'jumped' and then kept chugging.

I see you are the central time zone.
Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on January 11, 2015, 07:06:56 PM
boB, winks, hints, nudges, pokes, whatever it takes :)

If Mario wants to test anything in the field, have him get a hold of me.  I have no critical loads and enjoy testing.

Westbranch, central Iowa, US.
Title: Re: Beaglebone black DVM pods and graphs
Post by: TomW on February 04, 2015, 12:51:56 PM
Quote from: xsnrg on January 11, 2015, 07:06:56 PM
Westbranch, central Iowa, US.

Hmmm, we are in the process of moving about 18 miles NE of you if our house renovation ever gets completed.

Not a lot of RE folks in the corn patch that I am aware of. Certainly not up here in Decorah where we live now!

Our paths may cross some day, especially if you are any kind of shooting sports enthusiast.

Tom
Title: Re: Beaglebone black DVM pods and graphs
Post by: xsnrg on February 04, 2015, 09:53:24 PM
Agree on all counts.  Our paths will likely cross.  I would look forward to it.