Hello,
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.
void setup() {
Serial.begin(9600);
// delay(1000);
while (!Serial);
Serial.println("SETUP");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
Serial.println("Hello World!");
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
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!
Terje