I uploaded to my Arduino RP2040 the following sketch

#include <ArduinoBLE.h>
#include <Arduino_LSM6DSOX.h>

#define BUFFER_SIZE 64

BLEService service("180F");
BLEUnsignedCharCharacteristic accellerometerChar("0001",  // standard 16-bit characteristic UUID
    BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes

int oldBatteryLevel = 0;  // last battery level reading from analog input
long previousMillis = 0;  // last time the battery level was checked, in ms

int i = 0;
float buffer[BUFFER_SIZE];

void setup() {
  Serial.begin(9600);    // initialize serial communication
  while (!Serial);

  pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected

  // avvio del bluetooth
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");
    while (1);
  Serial.println("Bluetooth device attivo, in attesa di connessione...");

  //Avvia dell'accellerometro
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  Serial.println("Unità IMU inizializzata...");
   *  Impostazioni dei parametri del servizio
  BLE.setAdvertisedService(service); // add the service UUID
  service.addCharacteristic(accellerometerChar); // add the battery level characteristic
  BLE.addService(service); // Add the battery service
  accellerometerChar.writeValue(oldBatteryLevel); // set initial value for this characteristic

  // start advertising


void loop() {
  // wait for a BLE central
  BLEDevice central = BLE.central();


  // if a central is connected to the peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    digitalWrite(LED_BUILTIN, HIGH);

    // check the battery level every 200ms
    // while the central is connected:
    while (central.connected()) {
      long currentMillis = millis();
      // if 200ms have passed, check the battery level:
      if (currentMillis - previousMillis >= 200) {
        previousMillis = currentMillis;
    // when the central disconnects, turn off the LED:
    digitalWrite(LED_BUILTIN, LOW);
    Serial.print("Disconnected from central: ");

void readSensoreAccellerometetro(){
  float x, y, z;
  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);
    buffer[i] = sqrt( abs(x)* abs(x) + abs(y) * abs(y) + abs(z) * abs(z));
    if (i > BUFFER_SIZE){
      i = 0;

void updateAccellerometerLevel() {
  float batteryLevel = 0;
  float tot = 0;
  for(int i = 0; i < BUFFER_SIZE; i++){
    tot += buffer[i] * buffer[i];
  batteryLevel = sqrt( tot  ) / BUFFER_SIZE;
  if (batteryLevel != oldBatteryLevel) {      // if the battery level has changed
    Serial.print("Accellerometro : "); // print it

    int val = (int) (batteryLevel * 100);
    accellerometerChar.writeValue(val);  // and update the battery level characteristic
    oldBatteryLevel = batteryLevel;           // save the level for next comparison

now the device is blinking forever. and I'm not able to upload any new sketch. If a try the IDE waits few minutes and gives the following generic message

Errore durante il caricamento dello sketch

as if it is not able to use the serial port.

Is it possible to reset the board to facortory settings? I've already tried with the reset button and with the reset pin. What in my sketch must be avoided to get in this situation?


2 Answers 2


Honestly, that was really easy to find this article, which seems to explain a lot.

First thing you can try is to try to force bootloader mode by double-pressing the reset button. Once there, you can try to upload another sketch from IDE. If it works, press reset again to exit bootloader mode.

  • 1
    \$\begingroup\$ Answers here are expected to stand alone even if the link goes down or becomes stale. Can you paraphrase a summary of the steps recommended in that article directly into your answer? (reference) \$\endgroup\$
    – nanofarad
    Commented Oct 6, 2021 at 20:50
  • \$\begingroup\$ If you double tap the reset button Arduino goes into an operation mode that allow to upload a new sketch \$\endgroup\$ Commented Oct 6, 2021 at 20:58
  • \$\begingroup\$ Agreed, this is essentially a link-only answer. If the link breaks, this answer won't be useful. \$\endgroup\$
    – JYelton
    Commented Oct 6, 2021 at 21:13
  • 1
    \$\begingroup\$ Edited my answer to include an explanation how to force bootloader mode from the link to answer. \$\endgroup\$
    – NStorm
    Commented Oct 7, 2021 at 5:56
  • \$\begingroup\$ I added as an answer what worked for me of the link above hopping that may be useful to somebody else \$\endgroup\$ Commented Oct 7, 2021 at 12:40

In my case I simply double tapped on the reset button. My Arduino got in a mode where not sketch was executed then I was able to upload a new sketch (i.e. bilker) as usual. Eventually I disconnected the USB power and reconned my Arduino board to power.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.