LCD Secondary Battery

Is it possible to show the battery level of the secondary battery (i.e. the one from the power expander) on the LCD screen? I currently have our main battery, and our backup battery showing, but I would like to know the charge of the secondary battery as well.

Thanks!

from the instructions:

.

EDIT:
run a cable from the ‘status’ port on the power expander and into a analog input. (I missed that part of the instructions in the quote)

Okay. So to get the battery level, I would do:


sprintf(firstLine, "1:%1.2fv  2:%1.2fv", nImmediateBatteryLevel/1000.0, SensorValue[in3]/45.6);

When I do that, I get .02V. I don’t think that’s correct.

Here is the rest of the code:

			while(nLCDButtons != 0)
			{
				sprintf(firstLine, "1:%1.2fv  2:%1.2fv", nImmediateBatteryLevel/1000.0, SensorValue[in3]/45.6);
				displayLCDString(0, 0, firstLine);
				sprintf(secondLine, "<Auton   B:%1.2fv", BackupBatteryLevel/1000.0);
				displayLCDString(1, 0, secondLine);
			}
			while(nLCDButtons != LeftButton)
			{
				sprintf(firstLine, "1:%1.2fv  2:%1.2fv", nImmediateBatteryLevel/1000.0, SensorValue[in3]/45.6);
				displayLCDString(0, 0, firstLine);
				sprintf(secondLine, "<Auton   B:%1.2fv", BackupBatteryLevel/1000.0);
				displayLCDString(1, 0, secondLine);
			}

EDIT: Okay, this is really weird. The 0.02V has slowly gone up to 2.28… It is still climbing… Is this normal?

The code looks OK (unless you have a newer power expander then use divide by 70 instead).

Check you are connected the right way, if you remove the cable from the analog port it should display around 5.4V with the code you have. Is the green led illuminated on the power expander ?

We got it working. For future reference for others, we casted SensorValue as a float and had to use the 270ish divisor. I’m not sure why, but the divisor needed to be slightly higher than 270…

Also, the expander battery was reporting a value of 8.3V but when swapped with the main battery (whose voltage was read at 7V by the cortex), was read slightly incorrectly at 7.1V, acceptable error. Even more oddly was that the off battery was also showing a weird reading, I think Jesse said 2.3V.

I know Jesse is more than competent to respond, but I wanted to say something before many replies are made to a resolved issue.

You are correct, the numbers on the Wiki assume 10 bit A to D and ROBOTC is 12 bit.

I usually convert to the same units as the other batteries (ie. mV), here’s an extract from some of my old code.

#if defined( BATERY_2_PORT )
        // NC1, A or A1 power expander 182/volt
        battery2Level = (int)((float)SensorValue BATERY_2_PORT ] * 5.46);
        // try and auto detect a new power expander, over 9000, probably an A2
        if( battery2Level > 9000 )
            // A2 power expander level 280/volt
            battery2Level = (int)((float)SensorValue BATERY_2_PORT ] * 3.57);
#endif