Arduino Leonardo + RTC PCF8563 + N5110 display + LM335 temp sensor

Hi guys,

I’m new in the arduino world (I’m using one about 2 weeks or so) and I’m having a few problems displaying date and time on a Nokia 5110 display.
I can run the display and the LM335 temperature sensor with the Adafruit librarys (Adafruit_GFX.h and Adafruit_PCD8544.h) and I can run the RTC with no problems. The problem is when I try to display the time and nothing shows on the display, but the RTC still working fine, because the serial monitor updates as it should.

I had tried this with two methods: using tronixstuff’s code and using the Rtc_Pcf8563.h library. In booth cases the problems persists.

Here are the booth codes:

#include "Wire.h"
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

#define PCF8563address 0x51

Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

int sensorPin = 0;

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String days[] = {"Domingo", "Segunda", "Terca", "Quarta", "Quinta", "Sexta", "Sabado" };
 
byte bcdToDec(byte value)
{
  return ((value / 16) * 10 + value % 16);
}
 
byte decToBcd(byte value){
  return (value / 10 * 16 + value % 10);
}
 
void setPCF8563()
// this sets the time and date to the PCF8563
{
  Wire.beginTransmission(PCF8563address);
  Wire.write(0x02);
  Wire.write(decToBcd(second));  
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));    
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(dayOfWeek));  
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.endTransmission();
}
 
void readPCF8563()
// this gets the time and date from the PCF8563
{
  Wire.beginTransmission(PCF8563address);
  Wire.write(0x02);
  Wire.endTransmission();
  Wire.requestFrom(PCF8563address, 7);
  second     = bcdToDec(Wire.read() & B01111111); // remove VL error bit
  minute     = bcdToDec(Wire.read() & B01111111); // remove unwanted bits from MSB
  hour       = bcdToDec(Wire.read() & B00111111);
  dayOfMonth = bcdToDec(Wire.read() & B00111111);
  dayOfWeek  = bcdToDec(Wire.read() & B00000111);  
  month      = bcdToDec(Wire.read() & B00011111);  // remove century bit, 1999 is over
  year       = bcdToDec(Wire.read());
}
 
void setup()
{
  Wire.begin();
  //Serial.begin(9600);
  display.begin();
  display.setContrast(50);
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();
  // change the following to set your initial time
  second = 0;
  minute = 36;
  hour = 18;
  dayOfWeek = 4;
  dayOfMonth = 19;
  month = 9;
  year = 13;
  // comment out the next line and upload again to set and keep the time from resetting every reset
  //setPCF8563();
}
 
void loop()
{
  readPCF8563();
  Serial.print(days[dayOfWeek]);
  Serial.print(" ");  
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/20");
  Serial.print(year, DEC);
  Serial.print(" - ");
  Serial.print(hour, DEC);
  display.setCursor(0,0);
  display.print(hour, DEC);
  //display.display();
  Serial.print(":");
  display.setCursor(20,0);
  display.println(":");
  //display.display();
  if (minute < 10)
  {
    Serial.print("0");
    display.setCursor(25,0);
    display.println("0");
    //display.display();
  }
  Serial.print(minute, DEC);
  display.setCursor(31,0);
  display.print(minute, DEC);
  display.setCursor(40,0);
  display.println(":");
  //display.display();
  Serial.print(":");  
  if (second < 10)
  {
    Serial.print("0");
    display.setCursor(45,0);
    display.println("0");
    display.display();
  }  
  Serial.println(second, DEC);
  Serial.print(temperature());
  Serial.println("ºC");
  display.setCursor(51,0);
  display.print(second, DEC);
  display.display();
  display.setCursor(60,41);
  display.println(temperature());
  display.display();  
  delay(1000);
  
  display.clearDisplay();
  
  
}

float temperature(){
  int reading = analogRead(sensorPin);
  float voltage = (reading) * 5.0;
  voltage /= 1024.0;
  float temperatureC = (voltage - 0.5) * 10;
  
  return temperatureC;
}
#include <Rtc_Pcf8563.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Wire.h>

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

int sensorPin = 0;

Rtc_Pcf8563 rtc;

void setup()   {
  
  Serial.begin(9600);  // initialize the serial port
  
  //clear out the registers
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century(1=1900, 0=2000), year(0-99)
  //rtc.setDate(19, 4, 9, 0, 13);
  //hr, min, sec
  //rtc.setTime(18, 05, 50);
  
  
  //analogWrite(11,10);
  display.begin();
  // init done

  // you can change the contrast around to adapt the display
  // for the best viewing!
  display.setContrast(50);

  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer

}

void loop()
{
  //both format functions call the internal getTime() so that the
  //formatted strings are at the current time/date.
  Serial.print(rtc.formatTime(RTCC_TIME_HMS));
  Serial.print("\r\n");
  Serial.print(rtc.formatDate(RTCC_DATE_WORLD));
  Serial.print("\r\n");
  
  
  
  //display.setTextSize(2);
  //display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.print(rtc.formatTime(RTCC_TIME_HMS));
  
  //display.setTextSize(1);
  display.setCursor(0,21);
  display.print(rtc.formatDate(RTCC_DATE_WORLD));
  
  display.setCursor(60,41);
  display.println(temperature());
  display.display();
  
  delay(1000);
  display.clearDisplay();
}

float temperature(){
  int reading = analogRead(sensorPin);
  float voltage = (reading) * 5.0;
  voltage /= 1024.0;
  float temperatureC = (voltage - 0.5) * 10;
  
  return temperatureC;
}

On the second code, the screen stops working after the rtc is called. If I comment the RTC functions and try to display something else (like the temperature) it works like a charm, but it fails when I insert the functions related to the RTC…

Anyone can help me?

Anyone please? :(