Hi everyone, I have a problem with the RTC module. I'm using a DS1307 rtc and an Arduino Mega. When I upload the sketch the rtc should take the hour of the computer, but actually it results to be on late of about 5-6 seconds respect to the clock of the computer.
I use this "classic" sketch:
// Date and time functions using a DS1307 RTC connected via I2C
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void loop () {
DateTime now = rtc.now(); //recupera data e ora corrente
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(10000);
}
I also tried to use a DS 3231, witch is more accurate than the other one, but the result is the same: the rtc module loses some seconds respect to the clock of the computer.
Battery clocks with their own time keeping crystals drift. Its a fact of life. Code an easy way to reset the time. This happens to all battery clocks to more or less extent (unless sync'd to WWV or WWVB or satellite). I have four clocks I built with RTC's and they all drift at different rates, mostly fast.
Using compilation time is a rather crude way of updating the RTC.
But once the RTC has been set with a time, does the time shift from the PC time say constant. That is, is it always say 5 seconds slow or does it continue to get worse .
Okay, I understood. And how did you wrote this function? Would you like to share your code? I tried to search this part in the project you linked before, but I didn't found it...sorry I'm not very skilled with Arduino yet
Hi,
The DS1307 is a low-precision RTC. The DS3231 has a higher precision, but still needs an adjustment for each case.
I have one here at home that advances about 1 second every 2 months in relation to the NTC time.
But it seems that this is not the problem you are having.
If I'm wrong, correct me.
You want to set your RTC with the same "time" as your note book,
but there is an initial delay between your RTC being adjusted and therefore it is a few seconds behind the note. This is it?