NGUYỄN VĂN SUM

Wednesday, November 15, 2017

DS3231 Real Time with Arduino display on LCD_I2C

/*
* DS3231 Real Time with Arduino display on LCD_I2C
*
Crated by Nguyen Sum,
https://nguyensumiot.wordpress.com/
http://nguyensum.simplesite.com/
*
* DS3231 Library made by Henning Karlsen which can be found and downloaded from his website, www.rinkydinkelectronics.com.
*
*/
#include
#include
#include
//#include // includes the LiquidCrystal Library
DS3231 rtc(SDA, SCL);
//LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)

//LiquidCrystal_I2C lcd(0x27,20,4);// set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27,16,2);// set the LCD address to 0x27 for a 16 chars and 2 line display
// PINS CONNECT FROM I2C WITH ARDUINO
// Arduino Uno: SDA to A4; SCL to A5
// Arduino Mega 2560: SDA to 20; SCL to 21

void setup() {
Serial.begin(9600);
rtc.begin(); // Initialize the rtc object
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }

lcd.init(); //Khởi động màn hình. Bắt đầu cho phép Arduino sử dụng màn hình, cũng giống như dht.begin() trong chương trình trên
lcd.backlight(); // bat den nen lcd

}
void loop() {
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());

lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());


// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());


delay(1000);


}

No comments:

Post a Comment