Arduino unr r4 mini doesn't reconnect to serial port after manual reset

I'm testing the Uno R4 Minima and tried a simple sketch:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);

  //make sure the computer is actually waiting for the arduino
  bool synced == false;

  while(not synced) {

    //wait for serial input
    while(Serial.available() == 0) {
      Serial.println("sync");
      delay(1000);
    }//while(Serial.available() == 0)

    //get serial input
    String recieved = Serial.readStringUntil('\n');

    //if synced, break outer loop
    if(recieved == "synced"){
      Serial.println("synced");
      synced = true;
    }
    
    else{
      Serial.println("not synced");
    }

  }//while(not synced)
}// void setup

If I hit the reset button, the serial port seams to close as I can't reopen the serial monitor and have to manually reselect the port in the "tools"-menu.
I don't understand what's going on and would like to know how to avoid this.
With the old Uno R3 it worked perfectly fine.

I found a solution thanks to @KurtE in this post.
The line
while (!Serial && (millis() < 5000));
let's the R4 reconnect correctly after reset. For explanation, see the original post.

That may not work with all computers. When you reset the USB port disconnects then when it reconnects your computer re-enumerates the USB port. Generally but not always it will come back the same. On my machine it changes to generally the next higher port.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.