arduino / arduino/ArduinoCore-renesas

[UNO R4 WIFI] - periodicCallback() does not seem to work correctly as long as it includes Serial.println().

Open
#138 4 comments 0 reactions 0 assignees Claimed by @delta-G View on GitHub
topic: code type: imperfection
Dominant language
C
Stars
193
Forks
112
PR merge metrics
No merged PRs in 30d

Description

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.)

Another strange thing is that when I comment out the line of code `Serial.println("PERIODIC INTERRUPT");` in the `periodicCallback()` function, the LED can blink once every two seconds as expected.

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.

![156372dc3448e24e7c88397cd2bde6d6286fe72d_2_664x499](https://github.com/arduino/ArduinoCore-renesas/assets/32332228/f2a23c73-15ee-4b81-9abe-258e4b552ca1)

I also reported this issue on the Arduino community forum, see [this link](https://forum.arduino.cc/t/there-may-be-some-conflict-between-rtc-and-the-serial/1169836).

A kind-hearted person tested my code and obtained the same result. https://forum.arduino.cc/t/there-may-be-some-conflict-between-rtc-and-the-serial/1169836/5?u=wulu

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the UNO R4 WiFi periodic-interrupt example and reproduce the interaction between RTC.setPeriodicCallback() and Serial.println() in periodicCallback(). Compare the WiFi and Minima behavior using the reported firmware and library versions. Done means the LED blinks every two seconds and the complete serial message is printed while Serial.println() remains enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.