Hi and thanks in advance for any help.
Basically, I'm working on a light dimmer project (first ever) and am running into some trouble with the RTC. I have a DS1307 that came with my starter kit from Elegoo and it won't update the time. I'm able to communicate with it and the serial monitor shows that it is running but the time doesn't change. I'm using the adafruit RTC library: GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library and using the examples that it includes.
I know I am communicating with the module as I have been able to change the date/time (but now can't) and the softRTC example works just fine but I would rather use actual date/time rather than just elapsed millis()
I used the included example "ds1307"
[code]
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
// while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(57600);
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();
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();
Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));
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);
}
[/code] with the line to update the date/time to current upload date/time as active. It shows the date/time that was stored in the module from another library that I tried... This is also the case when I try to manually set the date/time using the "// January 21, 2014 at 3am you would call:" example.
Before I tried the other libraries, it updated the date/time to current with upload but would not progress. When I use the softRTC it auto updates to current date/time of upload and proceeds appropriately. Do you think this is a hardware or program issue? I am stumped!
Thanks again!
Scott


