004 Date and time on LCD with Arduino language

1. Forewords

This is the same example as here but adapted to work also with LCD (this not exclude the need of using the console - you need it to set the time and date).

2. Set the board

Insert the LCD if is not connected already. Do the following wire connections:

Start Arduino IDE and write the sketch bellow:

3. The sketch

#include <Wire.h> // necessary, or the application won't build properly #include <stdio.h> #include <PCF8583.h> #include <LiquidCrystal.h>

/***************************************************************************** * read/write serial interface to PCF8583 RTC via I2C interface * * You can set the type by sending it YYMMDDhhmmss; * the semicolon on the end tells it you're done... * ******************************************************************************/ int correct_address = 0;

PCF8583 p (0xA2);// the device's I2C read address on our board LiquidCrystal lcd(22, 23, 24, 25, 26, 27);

void setup(void){

Serial.begin(9600);

Serial.print("booting...");

Serial.println(" done");

// set up the LCD's number of columns and rows: lcd.begin(16, 2);

// Print a message to the LCD. lcd.print("booting... done!");

delay(1000);

lcd.setCursor(0, 0);

lcd.print(" ");

}

void loop(void){

if(Serial.available() > 0){

p.year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)) + 2000;

p.month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));

p.day = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));

p.hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));

p.minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));

p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));

// Use of (byte) type casting and ascii math to achieve result. if(Serial.read() == ';'){

Serial.println("setting date");

p.set_time();

}

}

p.get_time();

char date[9];

sprintf(date, "%02d/%02d/%02d",

p.year, p.month, p.day);

lcd.setCursor(0, 0);

lcd.print(date);

// char time[9];

sprintf(time, "%02d:%02d:%02d",

p.hour, p.minute, p.second);

//Serial.println(time); lcd.setCursor(0, 1);

lcd.print(time);

delay(990);

}

4. Results

As you can see this is an old movie because the wire connections are different. Just stick with our example. Anyway, the result is the same.