Deviation in synchonization RTC3231

I synchronized my real time clock (RTC3231) with the following instruction

RTC.adjust(DateTime(DATE, TIME)); //Set the date and time unconditionally

The time on my computer display is 12 seconds earlier than the readout of my RTC.
computer versus RTC: 20:00:12 versus 20:00:00

I expected that this times should be equal.
Has anybody an explanation?

Where are DATE and TIME set in the sketch ?

You are setting the RTC to the time the sketch was compiled, there are a few things that the IDE does afterwards to actually write the code to the arduino, verify it was written correctly, then reset the arduino so the code is executed. After a reset, the arduino bootloader also waits a couple of seconds before actually executing your code.

Since you know that takes a total of about 12 seconds, modify the sketch to set the RTC to the current time plus 12 seconds. Another method is to put a specific time in the sketch, then set the RTC to that time when a button is pressed, so you can watch the clock and press the button at the appropriate time.

Here
bildr ยป Do You Have The Time? DS1307 RT Clock + Arduino
are two programmes. The second sets the time when the reset button is released.

Also remember that "DATE" and "TIME" are not dynamic, so if you leave the line of code in the sketch, the clock will be reset to compile time every time the arduino is powered up.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.