Error trying to print temperature from DS3231 on 5110 lcd screen.

Hello! :slight_smile:

I am trying to build a custom speedometer for my scooter but I face difficulties when I attempt to print the temperature reading from the DS3231 to my 5110 lcd screen. I can print the temperature using the serial monitor (using serial.print command) but it is impossible to do the same on the lcd.

Here is the code

#include <LCD5110_Graph.h>
#include <DS3231.h>


// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

//Init the lcd
LCD5110 myGLCD(8,9,10,12,11);
extern uint8_t SmallFont[];
extern unsigned char TinyFont[];

int speed = 0;


void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  
  // Initialize the rtc object
  rtc.begin();
  // Initialize the lcd screen
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  randomSeed(analogRead(7));
  
  // Uncommente to set the date and time
  //rtc.setDOW(FRIDAY);     // Set Day-of-Week to MONDAY, TUESDAY etc.
  //rtc.setTime(22, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(19, 1, 2018);   // Set the date to January 1st, 2014
}

void loop()
{
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myGLCD.print(rtc.getTimeStr(FORMAT_SHORT), LEFT, 0); // Remove FORMAT_SHORT FOR SECONDS
  myGLCD.print("36528km", RIGHT, 0);
  myGLCD.setFont(TinyFont);
  myGLCD.print(rtc.getDateStr(FORMAT_SHORT), LEFT, 8);// Remove FORMAT_SHORT FOR FULL YEAR
  myGLCD.print(rtc.getTemp(), CENTER, 20);
  if (speed == 0)
  {
  myGLCD.setFont(SmallFont);
  myGLCD.print("JOG", CENTER, 20);
  }
  else
  {
  myGLCD.print(speed, CENTER, 20);
    }
  myGLCD.drawRect(28, 18, 56, 28);
  for (int i=0; i<6; i++)
  {
    myGLCD.drawLine(57, 18+(i*2), 83-(i*3), 18+(i*2));
    myGLCD.drawLine((i*3), 28-(i*2), 28, 28-(i*2));
  }
  myGLCD.setFont(TinyFont);
  myGLCD.print("Voltage: ", LEFT, 35);
  myGLCD.print("Fuel:E[************]F", LEFT, 42);
  myGLCD.update();
  
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Send current temperature
  Serial.print("Θερμοκρασία: ");
  Serial.print(rtc.getTemp());
  Serial.println("C");
  
  // Wait one second before repeating :)
  delay (1000);
}

The error messages I get when compiling

C:\Users\cabrinha\Desktop\konter\konter.ino: In function 'void loop()':

konter:42: error: no matching function for call to 'LCD5110::print(float, int, int)'

   myGLCD.print(rtc.getTemp(), CENTER, 20);

                                         ^

C:\Users\cabrinha\Desktop\konter\konter.ino:42:41: note: candidates are:

In file included from C:\Users\cabrinha\Desktop\konter\konter.ino:1:0:

C:\Users\cabrinha\Documents\Arduino\libraries\LCD5110_Graph/LCD5110_Graph.h:95:8: note: void LCD5110::print(char*, int, int)

   void print(char *st, int x, int y);

        ^

C:\Users\cabrinha\Documents\Arduino\libraries\LCD5110_Graph/LCD5110_Graph.h:95:8: note:   no known conversion for argument 1 from 'float' to 'char*'

C:\Users\cabrinha\Documents\Arduino\libraries\LCD5110_Graph/LCD5110_Graph.h:96:8: note: void LCD5110::print(String, int, int)

   void print(String st, int x, int y);

        ^

C:\Users\cabrinha\Documents\Arduino\libraries\LCD5110_Graph/LCD5110_Graph.h:96:8: note:   no known conversion for argument 1 from 'float' to 'String'

exit status 1
no matching function for call to 'LCD5110::print(float, int, int)'

Thank you in advance.

Looks like your LCD library won't print numerical values, just text. Find a better library.

Hi,

Did you google 5110 lcd arduino

There are example there using a different library.

Tom... :slight_smile:

Thanks for your responses.

I converted rtc.getTemp from float to string and the problem solved.

float temperature = rtc.getTemp();
  String temp = String(temperature, 2);
  myGLCD.print(temp , RIGHT, 8);