Power Expander Battery Voltage

How can display the voltage on a LCD of the battery on my power expander?

Thanks in advance.

Status port, use it as analog sensor

What code do I have to write so it displays the voltage on the LCD?

I wrote an article about batteries that describes how to do this. Here’s a link directly to that part of the article: VEX Batteries: Performance & Measurement

Here’s something I helped a team put together a couple of years ago. They wanted a task to display both battery levels on the LCD. You probably don’t want all this, and you probably don’t need all the comments that are included in the source code. But I don’t want to take the time to delete any of that. Feel free to ask questions.

The following example is a task that reads the power of each of the two VEX batteries, (main and power expander, which we called ") formats the data as floating point numbers, and prints it on the LCD.
First, here’s what the pragma lines for sensors were set to:

#pragma config(Sensor, in2,    power,          sensorAnalog)


Here’s the task:

task monitorPower()
{
    // declare some string variables to hold the formatted information
    string mainBattery;
    string expanderBattery;
    // turn the integer value representing main battery millivolts into
    // a floating point value representing volts. Then, format the
    // the information for printing. The "%f" in the format string will be
    // replaced by the floating point number calculated by the division.
    sprintf(mainBattery," %f Volts",(float)nImmediateBatteryLevel/1000.0);

    // The power expander has a voltage sensor port. We plugged a
    // jumper wire (VEX extension cable) from the sensor port  on the
    // power expander to the analog sensor port # 2 on the Cortex.
    // The value read by the sensor must be divided by 270 in order to
    // convert it into volts. Also, we named the port "power". So:
    //
    // turn the integer value from sensor port #2 into a floating point value
    // representing volts of the battery plugged into the power expander.
    // Then, format the information for printing. The "%f" in the format
    // string will be replaced by the floating point number calculated by the
    // division.
    sprintf(expanderBattery," %f Volts",(float)SensorValue[power]/270.0);

    clearLCDLine(0);
    clearLCDLine(1);
    displayLCDString(0,0,mainBattery);
    displayLCDString(1,0,expanderBattery);
    // wait 1 second before reading the volts again. Just because.
    wait1Msec(1000);
}

The function that formats the data from a variable and creates something to display is “sprintf” and is traditionally pronounced “ess print eff”. That is, you pronounce the letter “s”, followed by the word “print”, followed by the letter “f”.
There are several related functions in C and all the languages that grew from that. I use them almost daily in my work. Here is a wikipedia article with some background:

Note that in the format specifier to sprintf, ”%f" is what you use for floating point numbers and “%d” is what you use for integers. Lots more detail on formatting options available here on this Linux Man Page for the function printf, which uses the same format specifiers as sprintf:

Here is a quick reference for printf:

Thanks, @kypyro!