Hi,
Back from C-19 leave, and still haven't figured this out. As noted at the top, I'm using the example source code provided, with three modifications
1. Comment lines 10-13 because they garble the outbound on my serial monitor
2. Copy and paste the RTC adjustment line outside of any condition statements, so that it is FORCEFULLY set every time the sketch is run
3. Commented out all of the irrelevant lines that compute and print the seconds remaining until a future date.
Code
Code: Select all
// Date and time functions using a PCF8523 RTC connected via I2C and Wire lib
#include "RTClib.h"
RTC_PCF8523 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(57600);
// while (!Serial) {
// delay(1); // for Leonardo/Micro/Zero
// }
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.initialized()) {
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));
}
//FORCE INIT
rtc.adjust(DateTime(F(__DATE__), F(__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(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, 12 hours and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));
Serial.print(" now + 7d + 12h + 30m + 6s: ");
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);
}
Output:
10:06:54.487 -> ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
10:06:54.495 -> SDK:2.2.2-dev(38a443e)/Core:2.6.3=20603000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-16-ge23a07e/BearSSL:89454af
10:06:54.529 -> 2021/9/11 (Saturday) 10:6:46
10:06:54.529 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:06:54.529 ->
10:06:54.596 -> scandone
10:06:54.596 -> state: 0 -> 2 (b0)
10:06:54.630 -> state: 2 -> 3 (0)
10:06:54.630 -> state: 3 -> 5 (10)
10:06:54.630 -> add 0
10:06:54.630 -> aid 2
10:06:54.630 -> cnt
10:06:54.664 ->
10:06:54.664 -> connected with spudnet, channel 8
10:06:54.702 -> dhcp client start...
10:06:55.080 -> ip:10.0.1.123,mask:255.255.255.0,gw:10.0.1.1
10:06:57.501 -> 2021/9/11 (Saturday) 10:6:46
10:06:57.501 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:06:57.501 ->
10:07:00.512 -> 2021/9/11 (Saturday) 10:6:46
10:07:00.512 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:00.512 ->
10:07:03.522 -> 2021/9/11 (Saturday) 10:6:46
10:07:03.522 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:03.522 ->
10:07:06.512 -> 2021/9/11 (Saturday) 10:6:46
10:07:06.512 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:06.512 ->
10:07:09.506 -> 2021/9/11 (Saturday) 10:6:46
10:07:09.506 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:09.506 ->
10:07:12.527 -> 2021/9/11 (Saturday) 10:6:46
10:07:12.527 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:12.527 ->
10:07:15.505 -> 2021/9/11 (Saturday) 10:6:46
10:07:15.505 -> since midnight 1/1/1970 = 1631354806s = 18881d
10:07:15.505 ->