Hello fellow forum members, I just managed to connect my DS1302 RTC I bought from China to my Arduino UNO this week, but now I observed it drift in front of real time with about 19.89 seconds per day. I actually have 2 of them, and both do about the same drift. More exacly: From Date / Time: 2/6/2014 16:15:00 to Date / Time: 5/6/2014 20:23:56 the RTC drifted 63 seconds in front of real time.
I use the following code:
#include //|
// Creation of the Real Time Clock Object
//SCLK -> 5, I/O -> 6, CE -> 7
virtuabotixRTC myRTC(5, 6, 7);
void setup() {
Serial.begin(9600);
// Set the current date, and time in the following format:
// seconds, minutes, hours, day of the week, day of the month, month, year
/* SET TIME CODE:
myRTC.setDS1302Time(00, 15, 16, 7, 2, 6, 2014);
*/
}
void loop() {
// This allows for the update of variables for time or accessing the individual elements.
myRTC.updateTime();
// Start printing elements as individuals
Serial.print("Current Date / Time: ");
Serial.print(myRTC.dayofmonth);
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
// Delay so the program doesn't print non-stop
delay( 1000);
}
With the library: https://virtuabotix-virtuabotixllc.netdna-ssl.com/core/wp-content/uploads/2014/01/virtuabotixRTC.zip And code from here: https://www.virtuabotix.com/virtuabotix-ds1302-real-time-clock-module-pin-out-coding-guide/
My questions are: First one: Is there any way to use code to correct this drift daily? What can I do about it? Second question: Which is the easiest way to use the data read from the rtc to time varios things, like relay boards? Do I assign the data for each set of data separately to integers (get one for seconds one for minutes and so on) or use it as a string? I have to mention that I'm a newbie, did research on this but found nothing helpful, if you guys could point me to a tutorial or book to learn working with this kind of data it would be great.
Thank you for reading.
**Think this thread may go better in other subforum, about coding. I was thinking since it's about the sensor it should be in general electronics, but I just realised this after posting. Please move it if that's the case.