Hello everyone, when I tried to run the example in https://docs.arduino.cc/tutorials/uno-r4-wifi/rtc#Periodic-Interrupt, I found some errors in it.
In order to make the code run correctly, I made modifications to the code. The modified code is as follows:
// Include the RTC library
#include "RTC.h"
const int led = LED_BUILTIN;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
// Initialize the RTC
RTC.begin();
// RTC.setTime() must be called for RTC.setPeriodicCallback to work, but it doesn't matter
// what date and time it's set to
RTCTime mytime(30, Month::JUNE, 2023, 13, 37, 00, DayOfWeek::WEDNESDAY, SaveLight::SAVING_TIME_ACTIVE);
RTC.setTime(mytime);
if (!RTC.setPeriodicCallback(periodicCallback, Period::ONCE_EVERY_2_SEC)) {
Serial.println("ERROR: periodic callback not set");
}
}
void loop() {
}
// This is the callback function to be passed to RTC.setPeriodicCallback()
void periodicCallback()
{
static bool ledState = false;
if (ledState == true) {
digitalWrite(LED_BUILTIN, HIGH);
}
else {
digitalWrite(LED_BUILTIN, LOW);
}
ledState = !ledState;
Serial.println("PERIODIC INTERRUPT");
}
Unfortunately, when I uploaded the code to my Arduino R4 WiFi, its performance did not meet expectations.The LED did not blink at a two-second interval and it was unable to print the complete message on the serial monitor.
However, when I uploaded this code to Uno R4 Minima, everything worked fine.
(Additional information: The firmware version of Arduino R4 WiFi is 0.3.0, and the library version displayed in the board manager is 1.0.4.)
Does anyone know why this is? Or has anyone done the same test on the R4 wifi board? Thank you very much for any help.