Introduction
A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. The term real-time clock is used to avoid confusion with ordinary hardware clocks which are only signals that govern digital electronics and do not count time in human units.
evive has an inbuilt RTC IC, PCF8563. The IC gets power from the internal battery of evive so it can continue to keep time while the external source of power is off or unavailable.
PCF8563
The PCF8563 is a CMOS Real-Time Clock and calendar optimized for low power consumption. A programmable clock output, interrupt output, and a low voltage detector is also provided. All addresses and data are transferred serially via a two-line bidirectional IIC-bus. Maximum bus speed is 400 kbit/s. The registered address is incremented automatically after each written or read data byte.
It provides the year, month, day, weekday, hours, minutes, and seconds based on a 32.768 kHz quartz crystal. It also has a century flag, alarm and timer functions, integrated oscillator capacitor and internal Power-On Reset.
Read/Write on RTC in Arduino IDE
evive communicates with RTC via IIC-bus using wire.h library. Any data that comes in or comes out of RTC is in Binary-Coded Decimal (BCD) of eight bits.
Example
Given below is a sample code demonstrating how to read and write on RTC.
/*
evive RTC Write Operation
This code demonstrate how to set time on PCF8563 (a Real Time Clock) and get updated time from it.
Here intially time of RTC is set.After that time and date updated by rtc are printed on evive screen.
Explore more on: https://thestempedia.com/tutorials/rtc/
*/
#include <evive.h>
Rtc_Pcf8563 rtc;
String weekDay[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
void setup() {
tft.init(INITR_BLACKTAB);
tft.setRotation(1);
tft.fillScreen(ST7735_BLACK);
//Draw round rectangle border on evive screen
tft.drawRoundRect(2, 2, 156, 123, 10, ST7735_BLUE);
//Print evive logo on screen
tft.drawBitmap(45, 20, evive_logo, 71, 71, ST7735_BLUE);
//clears all registers
rtc.initClock(); //initialize clock
/* set a date to start with.
day, weekday, month, century, year */
rtc.setDate(14, 6, 3, 0, 10); // century 0 for 2000 and 1 for 1999.
/*set time in hr, min, sec format*/
rtc.setTime(1, 15, 40);
Serial.begin(9600);
}
void loop() {
//Get Date from RTC and print it on evive Screen
tft.setCursor(7, 7);
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.print(rtc.formatDate(0x01)); //0x01 for dd-mm-yyyy, 0x02 for yyyy-mm-dd ,0x04 for mm/dd/yyyy format
//Get weekDay from RTC and print it on evive Screen
tft.setCursor(135, 7);
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.print(weekDay[rtc.getWeekday()]);
//Get Time from RTC and print it on evive Screen
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setTextSize(2);
tft.setCursor(33, 100);
tft.print(rtc.formatTime(0x01)); //0x01 for Hours:minutes:seconds , 0x02 for Hours:Minutes
}
RTC on PictoBlox
In evive extension, there are blocks for the following purposes:
You can use these blocks in Stage Mode and Upload Mode.
Example
Here are some example scripts showing how to use the above blocks:
- In this program, we set the time on the clock to the present time and then we display it on evive’s TFT.
- In this program, we set the date on the clock to the present date and then we display it on evive’s TFT.
Conclusion
In conclusion, the PCF8563 is a CMOS Real–Time Clock and calendar optimized for low power consumption. It can be used in Arduino IDE or PictoBlox to read and write data to and from the RTC. The evive extension has blocks for setting the time, setting the date, and getting the time from the RTC. These blocks can be used in Stage Mode and Upload Mode in PictoBlox.