I have a RTC module DS1307 (MR005-001.2) on my Arduino Uno. I use the Wire.h / Time.h / DS1307RTC.h libraries.
The date and time returned is completely wrong ("17:18:9 2 4 2036") ... What do I do wrong ??
Thanks !
Here is my partial code for setup() :
setSyncProvider(RTC.get);
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
This writes "RTC has set the system time", so I guess something is happening right...
Here is my partial code for loop() :
Serial.print(hour());
Serial.print(":");
Serial.print(minute());
Serial.print(":");
Serial.print(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
Just as in the example ... and the date/time returned is "17:18:9 2 4 2036"
1 Answer 1
You setup interpretation should be more like:
setSyncProvider(RTC.get);
if(timeStatus()!= timeSet)
Serial.println("RTC has never been set");
else
Serial.println("RTC has a time");
To conditionally sync the clock to the compilation time if the clock is not running:
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
RTC.adjust(DateTime(__DATE__, __TIME__));
}
// following line unconditionally resets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
// RTC.adjust(DateTime(__DATE__, __TIME__));
To unconditionally sync it to the compilation time, uncomment the last line and reload for one cycle, then re-comment it and reload to let the clock run itself.
timeNotSet
is only if the library can't access the RTC module. The RTC module thinks it's 2036, and just keep incrementing the time, every second.