[SOLVED] Help! I think I bricked two MKR NB 1500s

I am trying to learn how to use/implement a watchdog timer. I was messing around with writing a test sketch and apparently bricked two MKR NB 1500 boards. I say I bricked them because after uploading the following sketch, I am getting a USB device error ("USB Device Not Recognized. One of the USB devices attached to this computer has malfunctioned, and Windows does not recognize it.") and neither board is showing up as connected in the Arduino IDE under the Tools > Port.

Here is the code:

#include <Arduino.h>
#include <Arduino.h>
#include <MKRNB.h>
#include <ArduinoLowPower.h>
#include <Adafruit_SleepyDog.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Serial monitor begin");

  //WDT Setup
  int wdtTimeout = Watchdog.enable(5000);
  Serial.print("WDT enabled with max timeout of ");
  Serial.print(wdtTimeout, DEC);
  Serial.println("ms");
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Now I'm in the loop");
  Watchdog.sleep(2000);
  Watchdog.reset();
}

Other details/comments:

  • Windows 10
  • Both boards were previously working fine.
  • I had previously uploaded a slightly different version of this same sketch which left out the last two lines of code (the watchdog.sleep and watchdog.reset) and was working fine (as in the board kept resetting since I wasn't resetting the wdt). It only appears to have bricked the board after I made this change. I have no idea why this code would have bricked a board, but both boards were working fine until I uploaded this exact code.
  • I initially wrote this code in VS Code & PlatformIO. After bricking the first board I copied the code into a new sketch in Arduino IDE and uploaded to the second board and had same results.
  • I know there are several library references that aren't needed in this sketch, they were copied from a previous sketch and I lazily didn't delete the ones that aren't being used in this sketch. Also noticed that I have the Arduino library twice.
  • I've tried different USB cables & ports
  • Tried restarting the computer

Any suggestions or ideas welcome! Thanks!

The tricky thing about putting the native USB boards like your MKR NB 1500 to sleep is that you are putting the microcontroller that creates the USB interface to sleep. So the USB interface needed to do uploads is lost when the chip is sleeping.

Fortunately, there is a way to put the microcontroller into bootloader mode, which will allow you to upload new sketches to it. You do this by pressing the reset button twice quickly. After that, you should see the "L" LED pulsing to indicate it's in bootloader mode. After that, select the board's port from the Tools > Port menu. The board may have a different port number when it is in bootloader mode, so don't assume you already have the right port selected. Now you can upload a new sketch to your Arduino board.

I am familiar with the risk/challenge of putting the board to sleep and being able to catch it while not sleeping to upload. I've been messing with sleep for a while, but had never had an issue like this where it was giving me a USB not recognized error like that.

But your tip worked! I had forgotten about the pressing reset twice to force bootloader mode. After that both boards were connecting successfully. Thanks so much!

You're welcome. I'm glad to hear it's working now. Enjoy!
Per