Hello, I am investigating an issue with the DS3231 RTC where it fails to display the 31st day of the month, rolling over to the 1st of the next month instead.
example:
On May 30, before midnight, the DS3231 RTC displays: 11:58:05 PM 05/30/2024 (HH:mm:ss MM/DD/YYYY)
After midnight, the DS3231 RTC displays: 12:00:01 AM 06/01/2024 (HH:mm:ss MM/DD/YYYY)
is this about something to do on my code ?
// REAL TIME CLOCK
Wire.begin(SDA_PIN, SCL_PIN);
if (!rtc.begin()){
Serial.println("Couldn't find RTC module");
while (1);
}
if (rtc.lostPower()){
Serial.println("RTC module lost power, setting the time");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
String currentDay = String(getRTC.day());
String currentTime = String(getRTC.hour()) + ":" + formatDigits(getRTC.minute());
String currentMonth = String(getRTC.month());
DateTime getRTC = rtc.now();
String currentMonth = String(getRTC.month());
Serial.println("Current Time: " + currentTime +" current Day: "+ currentDay + " Current Month: " + currentMonth );
You didn't supply a complete sketch that illustrated the problem you're describing. A snippet is a waste of time.
This sketch, uploaded to an Uno R3, with the RTClib, does not suffer from the problem you've described. It properly rolls over from May 30th to May 31st.
Thank you for pointing that out. I apologize for the mistake , I'm using
DS3231 RTC
ESP32 WROOM 32D
BAUD = 115200
#include <RTClib.h>
its a function to get time and i formatted only the values i need,
function timenow(){
DateTime getRTC = rtc.now();
String currentDay = String(getRTC.day());
String currentTime = String(getRTC.hour()) + ":" + formatDigits(getRTC.minute());
String currentMonth = String(getRTC.month());
Serial.println("Current Time: " + currentTime +" current Day: "+ currentDay + " Current Month: " + currentMonth );
}
setup(){
Serial.begin(115200);
// REAL TIME CLOCK
Wire.begin(SDA_PIN, SCL_PIN);
if (!rtc.begin()){
Serial.println("Couldn't find RTC module");
while (1);
}
if (rtc.lostPower()){
Serial.println("RTC module lost power, setting the time");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
timenow(); / / here i call it out just to confirm the value of rtc
}
I only displaying it once on serial just to know the month, I also tested on other month that has 31 on it and I've got same result, but on the 31st day I updated the time to 11:58:05 PM 05/31/2024 and it was running normal 12:00:05 AM 06/01/2024. only 31 missing when its day30.