I'm playing with the voltage monitor for my bot and using the GetADC(ADC Port) script command but having some slight issues with the values returned.
At first I thought it could be my code so I wrote a script to get the adc values from each of the ADC ports and add them as variables.Code:
$vc1 = GetADC(ADC0)
$vc2 = GetADC(ADC1)
$vc3 = GetADC(ADC2)
$vc4 = GetADC(ADC3)
$vc5 = GetADC(ADC4)
$vc6 = GetADC(ADC5)
$vc7 = GetADC(ADC6)
$vc8 = GetADC(ADC7)
In the variable watcher I have the following results - this is without anything connected to the ports.
Port Value
ADC0 32
ADC1 241
ADC2 136
ADC3 45
ADC4 14
ADC5 4
ADC6 1
ADC7 255
And when I attach the live of my cells (currently reading 4.09v & 4.06v) to the ADC signal on ADC0 and ADC1 I get
Port Value Description
ADC0 255 (4.09v cell)
ADC1 154 (4.06v cell)
Something isn't right surely? As far as I can see the GetADC command should report back a value between 0 and 255 for the voltage on the signal pin (0 being 0v and 255 being 5v), is that right? Do I have a problem with my board or software? Or have I not wired it correctly (I have nothing on the VCC and Gnd pins and the +v from each of the cells to ADC0 and ADC1)
Asked
— Edited
Code:
It's far from complete, the if's will eventually tell it to go charge up but for now just print a warning. The main thing is the values returned from the ADC ports.
Any help would be very much appreciated as I can't see what I'm doing wrong.
Edit: I just had a thought though, do I need to bring the ground from the battery to the ADC port too?
As I'm using a LiPo which are notorious for being dangerous if misused I'm hesitant to just go connecting things up "willy nilly"
I was a little puzzled by the adc values with nothing attached but maybe its nothing?
The lipo (long as it is below 5v) does not need to have the positive (+) connected. Only the GND (-) and Signal (+) should be connected. So connect the GND from the lipo to the GND on the ADC port. And connect the Positive from the lipo to the Signal on the ADC port.
However, I am currently using a 9v battery (obviously more than the 5v handled by ADC ports)... Is there a trick with ADC? or another way?
Such a simple problem and I could not solve it earlier for love nor money, yet now I look at it with a clear head (and the replies - thanks!) it's so obvious I have no idea how I missed it.
Thanks Dave & DJ. Now to make up a small lead and see what happens
As for voltage divers circuits, I did knock one up once but it was very primitave, just 2 resistors of equal value from Vcc to Ground, tap the signal off from between the 2 resistors... I don't have it drawn up though, but google voltage divider and a lot of examples come up.
I just made a voltage reducer because I wanted one of these ADC ports to monitor a 12v relay. I used a Zener Diode and a resistor to bring it down to 3.6 volts. The Z diode will give you a very stable voltage. Here's a couple links:
Also Rich's way of two resistors works great and is simple.
www.ehow.com/how_8341604_use-diode-reduce-dc-voltage.html
www.ehow.com/how_5819671_reduce-12-volt-system-volt.html
I think I will leave it just checking one cell, they are balanced and the charging is at 80mA on a 5000mAh battery so remains very balanced, it's not how I wanted it but it works.
I'll look in to it more when I get chance, I guess that's why I should have at least looked up the balance plug wiring configuration before doing this but no harm no foul I guess, I'm just glad the 8v to the ADC port didn't fry anything.
Edit: I tell you what, no sleep makes me forget the most simple of things. I know how a 2s lipo is wired yet totally forgot that. Ground to 1s is across 1 batter, ground to 2s is across both. 1s to 2s is across the other battery.
but, is it safe to connect the ground from ADC1 to the +v of battery 1 in order to measure the voltage across that battery?
Basically, the ADC signal can receive up to 5v, ADC read reports back a value between 0 and 255 depending on the voltage. 255 being 5v and 0 being 0v. So, to convert that figure to voltage you need to multiply the ADC read value by 5/255. Hopefully that made sense.
Chicken feet symbols? I don't know what symbol you are referring to... * or # ?
Code:
$factor is 5/255 which converts the ADC value to volts.
In the IF ($volts <3.5) you can change the 3.5 to whatever voltage you want it to tell you that it's low.
This is based on a battery of less than 5v, if you use a voltage reducer you would need to multiply $volts again, if halved the voltage multiply by 2, if quartered multiply by 4 etc.
I don't know how "clean" my code is, I generally end up with a lot of nests of IFs and ELSEs and a lot of variables that I suspect could probably be avoided. Feel free to alter it however you wish.
Edit: Replace the
* means multiply. So if you were to write a script $x = 2 * 2 then $x would be 4.
There was a thread here a few months ago about just this subject. Perhaps a search would be advised.
Black to Yellow is Cell 1. Black to Red is across both cells. Red to Yellow is across cell 2.
Stupidly I had done black/red to ADC1 which was feeding in up to 8.4v, so glad that didn't fry anything though.
I know I need to read from Red/Yellow but I don't know how safe it is to connect ADC1's Ground to the middle of the series of batteries. Hopefully a search will help though, now I know the problem it helps
By the way @Rich, i like the smiley in the code very much. We should ask DJ to implement it, it will make scripting a little more friendly
I just added it to examples in the cloud for those who want it and want to play around with it. It's called Battery Monitor. Or just click here
click here
with batteries full charge use resistors to get voltage as close to 5v without going over then just use ADC Value
But, with LiPos, you can't let them drain too much otherwise they don't charge, so ideally you want it to either a) shut off all power when it gets low or b) go and charge itself up. For those, it needs a script running to monitor and act upon a battery low alert.
My script doesn't give a graphical representation on screen for monitoring which is a downside but adding an ADC control in ARC would add that, at the cost of processing power as it would be checking twice as often.