Dear all,
The following code does not work the same on a arduino UNO R4 and a classical arduino (such as a nano):
void setup() {// the setup function runs once when you press reset or power the board
Serial.begin(9600); // setup serial
Serial.print("LED_BUILTIN = ");
Serial.println(LED_BUILTIN); // debug value
Serial.end(); // close serial link
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
}
void loop() {// the loop function runs over and over again forever
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a given time in ms
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(2900); // wait for a given time in ms
}
Nothing appears in the serial monitor.
Is serial printing unallowed with the uno r4 ?
Like @Juraj mentioned you may want to wait until the Serial object is ready, before outputting to it.
The Serial on the MINIMA is sort of like the Arduino Leonardo, in that instead of having some other chip or processor in it that does the USB, the main processor has USB support built into it. It takes a little time after the board boots up for the USB subsystem to startup and the host to be ready.
Note: typically, when I am waiting for the Serial to startup, I will put in some form of
timeout, so that the code won't wait forever. I have been bit more than once, where I then power up a board using external power connection and now USB and nothing works. And then remember I had the line: whille (!Serial);`
So I often do it something like:
void setup() {// the setup function runs once when you press reset or power the board
while (!Serial && (millis() < 5000); // wait up to 5 seconds.
Serial.begin(9600); // setup serial
Serial.print("LED_BUILTIN = ");
Serial.println(LED_BUILTIN); // debug value
Serial.end(); // close serial link
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
}
void loop() {// the loop function runs over and over again forever
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a given time in ms
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(2900); // wait for a given time in ms
}
Note: the line: while (!Serial && (millis() < 5000); // wait up to 5 seconds
assumes that this is done at startup where millis() is initialized to 0.
If you wish to do this in some later time, you might need a more generic version like:
uint32_t start_time = millis();
while (!Serial && ((millis() - start_time) < 5000); // wait up to 5 seconds.
"while (!Serial && (millis() < 5000); // wait up to 5 seconds" worked for me.
I spent alot of time trying to get a println on the monitor. Your help is
much appreciated.