Uploaded Sketch doesn't stick after reboot

Hi there!

I was playing around with the new nano 33 sense and the BLE example that is provided with the library. It works fine when the board is plugged into the Mac via USB, but once I disconnect from there and plug the board into a usb 5v charger the sketch doesn't seem to boot.
The LED on the left of the usb port on the board is solid green. If I press the reset button it goes out for a moment and return to solid green.
Oddly enough, when I press the reset button on the board twice in quick succession it turns on the yellow LED on the right of the USB port, which then proceeds to pulse on and off. But nothing happens in regards to the board showing up as a BLE peripheral, like it did when connected to the computer.

I had issues before with the Arduino IDE not recognising the board/usb-port since I might have mis-selected the board while using another Nano board (not the new sense ble). Maybe thats all related somehow.

My general questions are two:

-Can I reset the board completely (as in factory reset)?

-What are the functionalities of the reset button (apart from the obvious reset) and why does pulse yellow after being pressed twice?


It works fine when the board is plugged into the Mac via USB, but once I disconnect from there and plug the board into a usb 5v charger the sketch doesn’t seem to boot.

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click the “Reply” button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

-Can I reset the board completely (as in factory reset)?


-What are the functionalities of the reset button (apart from the obvious reset) and why does pulse yellow after being pressed twice?

When you press the reset button twice you put the board into bootloader mode, where it waits for an upload without running your sketch. The reason this is useful is because the USB code that causes your Nano 33 BLE Sense to be recognized as a serial port on your computer is running in the background on the same microcontroller your sketch code is running on. This means that a bug in your code can break the USB functionality and cause the Nano 33 BLE to no longer be recognized by the computer. That would break the ability to upload a new sketch. Luckily, the bootloader code that facilitates the uploads to the microcontroller runs in a special section that is not affected by your sketch code and runs its own USB code. So you can recover from that situation by putting the board in bootloader mode, selecting the port from the Arduino IDE’s Tools > Board menu (the board may have a different port when in bootloader mode than when running your sketch), and then doing an upload.

Thanks pert!

Now I understand the bootloader functionality better.
Underneath is the code I am trying to use with the Nano33.

  Callback LED
  This example creates a BLE peripheral with service that contains a
  characteristic to control an LED. The callback features of the
  library are used.
  The circuit:
  - Arduino MKR WiFi 1010 or Arduino Uno WiFi Rev2 board
  You can use a generic BLE central app, like LightBlue (iOS and Android) or
  nRF Connect (Android), to interact with the services and characteristics
  created in this sketch.
  This example code is in the public domain.

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service

// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

const int ledPin = 22; // pin to use for the LED

void setup() {
  while (!Serial);
  pinMode(ledPin, OUTPUT); // use the LED pin as an output

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);

  // set the local name peripheral advertises
  // set the UUID for the service this peripheral advertises

  // add the characteristic to the service

  // add service

  // assign event handlers for connected, disconnected to peripheral
  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  // assign event handlers for characteristic
  switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
  // set an initial value for the characteristic

  // start advertising

  Serial.println(("Bluetooth device active, waiting for connections..."));

void loop() {
  // poll for BLE events

void blePeripheralConnectHandler(BLEDevice central) {
  // central connected event handler
  Serial.print("Connected event, central: ");

void blePeripheralDisconnectHandler(BLEDevice central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");

void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
  // central wrote new value to characteristic, update LED
  Serial.print("Characteristic event, written: ");

  if (switchCharacteristic.value()) {
    Serial.println("LED off");
    digitalWrite(ledPin, HIGH);
  } else {
    Serial.println("LED on");
    digitalWrite(ledPin, LOW);
 while (!Serial);

On boards with a native USB port on the processor, this line causes the code to loop on the while() instruction until the USB port is connected. Since you are not connecting the USB cable to a computer, it will wait here forever.

Thanks for the solution.

Makes a lot of sense thinking about it.