Go Down

Topic: Sketch does not run after reset button or after USB out/in (Read 1 time) previous topic - next topic



I'm testing the simplest possible Serial Hello World example, combined with the Blink example. After upload (with the serial monitor already open), the sketch runs fine (diode blinks and serial output is correct). When closing and opening the serial monitor, the MKRZERO resets, and the monitor again displays the "SETUP" message from setup(), and then the "Hello World!" messages from loop() - and the diode blinks.

Code: [Select]
void setup() {
  // delay(1000);
  while (!Serial);
  pinMode(LED_BUILTIN, OUTPUT);   
void loop() {
  Serial.println("Hello World!");
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(LED_BUILTIN, LOW);

If I now press the RESET button on the MKRZERO, I hear the USB disconnect and USB connect sounds from the PC, but the sketch does not start - no serial output (if the monitor is already open), and no diode blinking.

The same happens if I physically disconnect the USB (powers down the board, since there is no battery) and reconnect the USB. I get PC sounds, but no serial output or blinking. The USB enumeration has (most often) not changed.

In both cases, as soon as I open the serial monitor, the program will start running.

Also, if I upload the code without the serial monitor already open, the program does not start.

I use Windows 10 version 1703, with a fresh Arduino 1.8.5 (installed today, after uninstalling, cleaning out Arduino from Program Files and from the User Documents, and running CCLEANER on files and registry), I only updated libraries as indicated by the interface, before trying this sketch.

Initially, the Serial.println() in the setup() function would never return an output. This problem was (sometimes) fixed by a delay(). It was also fixed by the while (!Serial); line. When using the delay() version, however, I sometimes find that the serial output does not re-appear after pressing the RESET button, while the diode blinking may resume (still without any Hello World!" output strings)!

I'm surprised by such a complex problem scenario from such a simple sketch, and I clearly hope for help from the forum!



The "while (!Serial);" is not needed on the MKR series boards.
Comment that out and check again.

That specifically waits until it sees a connection...hence your issue.
The reset also resets the connection too which also indicates the same as you have been seeing.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up