Display variable sensor data on Nokia 5110 LCD

Hello,

I want to display the real-time battery voltage on a screen connected to an Arduino UNO and i am using a Nokia 5110 LCD. I am using the libraries: Adafruit_GFX.h and Adafruit_PCD8544.h. I have managed to get variable data printed to the Serial Monitor but i cannot figure out how to show this same data on the LCD. :confused:

And here is the function to print to the LCD:

void volt_display(float length)
{
  Serial.println(length); //prints the actual battery voltage that needs to be displayed on LCD
  
  int batt_volt = voltage_msb << 2 | voltage_lsb >> 6;

  Volt[0] = ' '; // put space
  Volt[1] =  batt_volt / 40 + '0';          // batt_volt/40 = (batt_volt/4)/10 --> get tens
  Volt[2] = (batt_volt / 4) % 10 + '0';     // --> get ones
  Volt[4] = (batt_volt * 5) / 2 % 10 + '0'; // batt_volt*5/2 = (batt_volt/4)*10  --> get tenths
  Volt[5] = (batt_volt * 25) % 10 + '0';    // batt_volt*25  = (batt_volt/4)*100 --> get hundredths

  
  draw_text(12, 15, Volt);  // print voltage
  draw_text(52, 15, "Volts");  // print 'Volts'
}

What am i doing wrong? I want to display the voltage to 2 decimal places. I got this piece of code during my online research and i cannot really understand this part but i do recognise it as bit-wise operations:

 int batt_volt = voltage_msb << 2 | voltage_lsb >> 6;

Any help is appreciated. :slight_smile:

what happens when you use

  draw_text(12, 15, Volt,2);  // print voltage
Serial.println(Volt);

DryRun:
I want to display the real-time battery voltage on a screen connected to an Arduino UNO and i am using a Nokia 5110 LCD.

I started to learn how to use the LCD libraries: Adafruit_GFX.h and Adafruit_PCD8544.h

What am i doing wrong?

With the code you show, who would ever know? It rather depends on the library you are using, either of which should have examples included for thissort of stuff. If you can get what you want on the serial monitor e.g.
Serial.println(volts,2);
then, using the pcd84544 library,
lcd.println(volts,2);
should get the same result onto the display. Ultimately, you will need to work on lcd formatting, but I think you can get away without it to start with.

The 5110 will run off Arduino's 3.3v pin. Signal pins are 5v tolerant.