Opta hangs when disconnecting USB

If you connect a terminal to the Opta, for example the serial monitor, the Opta hangs if you pull out the USB. You can reproduce the problem with this test program:

void setup() {
  pinMode(LED_RESET, OUTPUT);
  Serial.begin(115200);
}
void loop() {
  if (Serial) Serial.println("Test");
  digitalWrite(LED_RESET, HIGH);  
  delay(1000);                     
  digitalWrite(LED_RESET, LOW);   
  delay(1000);                     
}

Just upload it to the Opta, connect the serial monitor to see the "Test" message every second. Then pull out the USB-cable, and then the Opta stops working.

A minor problem, but is it normal?

Is this using native USB?

Over native USB, Serial will hang - because it has no USB connection

Don't know if the USB is native, but I guess it is. I have to use the watchdog to get out of the situation.

Hmm ... the documentation says it should just return true if the Serial is available, and false if not:

So the code you showed shouldn't hang - it should just stop sending stuff to Serial.

If you start your Opta with the USB disconnected, does it work OK?

Maybe there is a bug - in that the status returned by Serial doesn't update if the USB is removed while running ... ?

Yes. It work well in all cases except when the USB comport on the windows pc is opened, and the connector is pulled out while the port is open.

So it does sounds like a bug, then - it doesn't recognise the state change.

I don't have anything with native USB to hand to see if other Arduinos do the same; ie, if it's a general bug on all platforms.

1 Like

Same Bug here. I was working on two Optas exchanging data.
Took me a while to figure out that the bugs were coming from switching USB Cable from one to another.
unplugging while running makes it freeze. Starting whithout cable don't.
Hope it will help people debugging two optas with one cable ...!

OPTA being in the Pro lineup… have any of you brought this up with Arduino Pro team? email support directly… this may be worth it so it gets their attention. Looks like they are on the OPTA forums but im not sure how much cause they do not chime in often…

Just a thought