5110 display arduino nano and rtc

Hi all,

I am using arduino nano with nokia 5110 display and rtc 3231. I meet with problem showing time on display.

code below is not working:

lcd.GotoXY(0,1);
  lcd.LcdString(t.hour);

main.ino

#include <Nokia5110.h>
#include <DS3231.h>

#define RST 8
#define CE 7
#define DC 6
#define DIN 5
#define CLK 4

LCDnokia5110 lcd(RST, CE, DC, DIN, CLK);


int temp;

DS3231  rtc(SDA, SCL);
Time t;



void setup() {
  Serial.begin(9600);
  rtc.begin();

  lcd.LcdInitialise();
  lcd.LcdClear();
  lcd.CharSpace = 1;
  lcd.GotoXY(15,0);
  lcd.LcdString("'C");
}

void loop() {
  temp = rtc.getTemp();
  t = rtc.getTime();

  lcd.GotoXY(0,0);
  lcd.LcdString(temp);
  lcd.GotoXY(0,1);
  lcd.LcdString(t.hour);
  lcd.GotoXY(0,2);
  lcd.LcdString(t.min);
  lcd.GotoXY(0,3);
  lcd.LcdString(t.sec);
}

nokia5110.h

#ifndef LCDnokia5110_h
#define LCDnokia5110_h

#include "Arduino.h"

class LCDnokia5110
{
  public:
    LCDnokia5110(int, int, int, int, int);
    void LcdClear();
    void LcdInitialise();
    void LcdWrite(byte, byte);
    void LcdString(char*);
    void LcdCharacter(char character);
    void GotoXY(int, int);
    void ShowLogo(int);
    void ShowImage(const unsigned char[], int);
    
    int CharSpace; 

  private:
    
};

#endif

If something missing, write please. Thank you :frowning: .

code below is not working:

More information please

What should it do ?
What does it do ?

On display are showed symbols and letters like @, :, A, etc. not time.

Hi

Check your DS3231.h file. I expect that time.hour is defined as a byte or unit8_t not a string. lcd.LcdString() is expecting a pointer to a string.

Ian

Thanks to the tip Ian, in DS3231.h is

class Time
{
public:
 uint8_t hour;
 uint8_t min;
 uint8_t sec;
 uint8_t date;
 uint8_t mon;
 uint16_t year;
 uint8_t dow;

 Time();
};

But I am not able to convert unit8 to string, or how to convert unit8 to display?

Interesting is, that serial.print(t.hour); not cause problem in Serial Monitor.

Hi

Check the definition of LcdString() in Nokia5110.h you will see it takes a pointer to a string. The code for Serial.print() is more flexible and will convert a variable to a string before printing.

Try the following:-

void loop() {
  temp = rtc.getTemp();
  t = rtc.getTime();
  
  char buffer[5];

  lcd.GotoXY(0,0);
  sprintf(buffer,"%2d",temp);
  lcd.LcdString(buffer);
  lcd.GotoXY(0,1);
  sprintf(buffer,"%2d",t.hour);
  lcd.LcdString(buffer);
  lcd.GotoXY(0,2);
  sprintf(buffer,"%2d",t.min);
  lcd.LcdString(buffer);
  lcd.GotoXY(0,3);
  sprintf(buffer,"%2d",t.sec);
  lcd.LcdString(buffer);
  delay(500);                         // only update every 1/2 second or the display may flicker
}

If you are going to print the year change the "%2d" to "%4d".

Ian