Need help how to restart the MKR ZERO

It wired me that the only way to start or restart the Sketch is upload the sketch.
My MKR ZERO is powered via a micrUSB cable, and I test some sample sketch to learn the MKR.
after upload the sketch, it runs well.
I want to restart the sketch, so I pressed the reset button, after that It appears the sketch isn't running. for example, I upload a sketch to let the LED blink, and It blinks well. when I pressed reset button, the PC's USB port disconnect and connect again, and the LED never blink again.

so what is the correct way to restart the sketch in the MKR ZERO?

Hi @stpanzj

Here's the recovery procedure for the MKRZero:

  1. Double tap the MKRZeros's reset button (two times in quick succession), this will place it in bootloader mode.

  2. Next, in the Arduino IDE menu select Tools->Port and then select the COM port. Repeat to check that the COM port is ticked.

  3. Now press the Arduino IDE's upload button oncemore.

On boards with a native USB such as the MKRZero, the board's microcontroller is responsible for maintaining the connection to your host PC/computer. However, if your sketch crashes the microcontroller for whatever reason, the board's auto upload functionality will also fail to operate, requiring the board to be manually set to bootloader mode with a double tap of the reset button.

Once a correctly functioning sketch has been uploaded in bootloader mode, the board's normal auto upload will start operating again.

Thanks. And how to force the MKR ZERO to run the sketch again?
I tested my MKR ZERO, uploaded the sketch to the MKR ZERO, It began to run the setup and then loop. I wanted to rerun the sketch, I tried two ways:

  1. power down and up. I unplugged the microUSB cable and plugged it again to the PC, the sketch did not run.
  2. press the button on MKR ZERO. I press the button once, the sketch did not run.
    the Sketch is to light the LED onBoard, so I can see if the sketch running.
    the Only way is to upload the sketch and it only ran one time. ANYWay to run sketch again?

Hi @stpanzj

Once a functioning sketch has been uploaded, it's possible to check if board is connected in the Arduino IDE by going to Tools->Port and checking that the COM port is ticked.

If the sketch is failing to restart properly then it's likely that there's a bug in your code somewhere, that's preventing the board from running.

Yes, you are right. I tried this sample sketch from File-Examples-01.basics-Blink:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

When I uploaded the sketch, the LED on board start to blink.
and I unplugged the microUSB cable, and plugged again, the sketch ran well as the LED was blinking.
Or I pressed the button, also it ran respectively.

But when I added some code to print message to the USB port, it appears something wrong. When I uploaded the modified sketch to the MKR Zero, the LED on board started to blink, and the Serial Monitor window started to output ".". Everythink is going well. But when I press the button or unplugged/plugged the cable, the LED never blink and the Serial Monitor window did not output anythink. So what's wrong with the code I had added? the following is the modified sketch:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  while (!Serial){}
  Serial.println("");
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  Serial.print(".");
}```

I think the code is doing the while sentencs, which is recomment to add waiting for native USB port only. That is to say the Serial is not start up properly. Is it a bug? or should I modify to make it work properly after reset the MRK Zero?

I removed: while (!Serial) {}, the Serial monitor did not received any char. and the LED blink as I expected.

Hi @stpanzj

I just tested your code on a custom SAMD21 board together with the Arduino IDE version 1.8.19 on a Windows PC. On my board, the COM port automatically recovers after either a standard (single press) reset or unplugging and plugging of the USB cable. The console continues outputting the '.' char and blinking the LED.

Are you using the lastest version of the Arduino IDE version 1.8.19?

just check that the version is 1.8.19(Windows Store 1.8.57.0).
Maybe the hardware you use is different from my MKR Zero.
I tested if I don't use
while (!Serial) {};
to wait the Serial get ready, all functions are normal except the Serial output.
So I think maybe the bug is: the Serial output did not handle well after reset the board.

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