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.
$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)
Ah, I see. I had though that was the case but wasn't sure.
Rich, I'm not familiar with these battery packs. Sounds like you have two cells wired in series? Wish I could see it and how it's wired. Off the top of my head; you could attach the negative from the load and the ground from the ADC port to the Negative of battery 1, the positive of battery is attached to Neg of Battery 2, the pos of battery 2 would be attached to your load and the Signal from the ADC port to Battery 2. However it sounds like this will bring the voltage above what the ADC port will handle. Put the Voltage divider in there like we mentioned above and I think you be OK and be able to monitor the entire pack. Again, I'd have to review the wiring of the pack before I would hook it up to my EZB. There was a thread here a few months ago about just this subject. Perhaps a search would be advised.
They are 2 cells wired in series. The balance port has 3 wires, black, yellow & red. 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
Thanks Rich and Dave for all these explanations and solutions. 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
One good thing to come out of this for me is it's inspired me to revisit my code (which is good because I needed a break from building and wiring). I'm just adding in some error checking, new variables for maximum and minimum voltages and multiplier for voltage division with the intention of sharing it (as I don't need the voltage division multiplier).
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
here is a easy way i watch all my voltages (total 4) with out a script click here with batteries full charge use resistors to get voltage as close to 5v without going over then just use ADC Value
That's a great way and it's how I would do it but doesn't get the EZB to run a command/task when battery is low, it just monitors it... which is fine if you just want to monitor it.
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.