I noticed this problem when writing a sketch to run a clock on an epaper display. It seemed to be running fast. Letting it go over night it seemed to go fast by about 1 second per minute. I then went back to the examples for Arduino UNO R4 WiFi : RTC : RTC_alarm. I made a simple change to use the LED Matrix to indicate the alarm, and then timed the duration between alarms using my iPhone clock. Sure enough, each alarm (supposedly 1 minute apart) was 1 second sooner each time.
I then hooked up a DS3231 I had sitting around, set the initial times to the same value on both the R4 RTC and the DS3231, and let the alarm demonstration run. This verified the fact that the alarm went off 1 second sooner than it should have each time it cycled around.
I went on step simpler and took out the alarm process and just went thru 1 minute delay cycles, and saw in the printout that the R4 RTC gains a second every minute.
Trying again with a 15 minute cycle time with this .ino code:
/*
* This example demonstrates the relative time of UNO R4 RTC vs DS3231
*
*/
#include "RTC.h" // R4 RTC
RTCTime currentTime;
#include "RTClib.h" //DS3231 Adafruit routines
RTC_DS3231 rtc;
DateTime now;
// Using the R4 LED matrix to indicate alarm in place of Portenta C33 built in LEDs
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
const uint32_t chip[] = {
0x1503f811,
0x3181103,
0xf8150000
};
const uint32_t happy[] = {
0x19819,
0x80000001,
0x81f8000
};
void setup() {
Serial.begin(115200);
matrix.begin();
rtc.begin();
RTC.begin();
rtc.adjust(DateTime(2023, 6, 7, 13, 03, 00)); // setting time of DS3231 in the same manor as R4 RTC
RTCTime initialTime(7, Month::JUNE, 2023, 13, 03, 00, DayOfWeek::WEDNESDAY, SaveLight::SAVING_TIME_ACTIVE);
RTC.setTime(initialTime);
now = rtc.now(); // getting time from DS3231
RTC.getTime(currentTime); // getting time from R4 RTC
Serial.println("Initial readout after time set");
Serial.println(String("DS3231 time: ") + now.timestamp(DateTime::TIMESTAMP_FULL));
Serial.println("R4 RTC time: " + String(currentTime));
Serial.println(" ");
}
int cycle_count = 0;
int next_time = millis();
void loop() {
while(millis()<next_time){
}
next_time += 60000*15; // one minute
now = rtc.now();
RTC.getTime(currentTime);
Serial.print("15min Cycle number ");
Serial.println(cycle_count);
Serial.println(String("DS3231 time: ") + now.timestamp(DateTime::TIMESTAMP_FULL));
Serial.println("R4 RTC time: " + String(currentTime));
Serial.println(" ");
cycle_count += 1;
}
I got the results:
Initial readout after time set
DS3231 time: 2023-06-07T13:03:00
R4 RTC time: 2023-06-07T13:03:00
15min Cycle number 0
DS3231 time: 2023-06-07T13:03:00
R4 RTC time: 2023-06-07T13:03:00
15min Cycle number 1
DS3231 time: 2023-06-07T13:18:02
R4 RTC time: 2023-06-07T13:18:16