Hi, I am using the softrtc example below along with a DS1307 breakout board
// Date and time functions using just software, based on millis() & timer
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime(__DATE__, __TIME__));
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" seconds since 1970: ");
Serial.println(now.unixtime());
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}
It works and my output on the serial monitor is correct
2012/7/25 22:42:39
seconds since 1970: 1343256159
now + 7d + 30s: 2012/8/1 22:43:9
2012/7/25 22:42:42
seconds since 1970: 1343256162
now + 7d + 30s: 2012/8/1 22:43:12
2012/7/25 22:42:45
seconds since 1970: 1343256165
now + 7d + 30s: 2012/8/1 22:43:15
However when I comment out the following line:
RTC.begin(DateTime(DATE, TIME));
I expect the readings to carry on as they were before with the same date and time as my PC but I am getting
2106/2/6 6:28:19
seconds since 1970: 3
now + 7d + 30s: 2106/2/13 6:28:49
2106/2/6 6:28:22
seconds since 1970: 6
now + 7d + 30s: 2106/2/13 6:28:52
2106/2/6 6:28:25
seconds since 1970: 9
now + 7d + 30s: 2106/2/13 6:28:55
which shows that the date and time set in the initial sketch is not being retained for some reason.
Any ideas on what is happening here?