ArduinoBLE reads occasionally wrong characteristic value

i am struggling with an issue on the RP2040 when i use the ArduinoBLE library. The characteristic can receive values from my iphone app in the range of [0, 100]. I occasionally read wrong values. The program also at some point (random time) simply freezes. This is most definitely not an iphone app issue, as the frequency the wrong values occur increases if i uncomment the mbed ticker. I also ran the code on a nano 33 BLE and i had no issues.
Would be great if you have an idea what this could be, if i did overlook something - or whether it might be a bug in the lib in connection with the RP2040.

Thanks a lot already!

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

//mbed::Ticker motor_ticker;

BLEService SliderService("7fc1c80a-d646-4198-8250-7a698e82e5a3"); // BLE LED Service
BLEIntCharacteristic SliderCharacteristicHorizontal("7fc1c80b-d646-4198-8250-7a698e82e5a3", BLEWrite);
BLEIntCharacteristic SliderCharacteristicVertical("7fc1c80c-d646-4198-8250-7a698e82e5a3", BLEWrite);

float ax, ay, az, gx, gy, gz; //IMU Data
int slidertest = 0, slidertest2 = 0;

//Initialise Functions
void SliderCharacteristicHorizontalWritten(BLEDevice central, BLECharacteristic characteristic);
void SliderCharacteristicVerticalWritten(BLEDevice central, BLECharacteristic characteristic);
void step_motor();

void setup() {

  //Serial Connection Initialisation

//  if (!IMU.begin()) {
//    Serial.println("Failed to initialize IMU!");
//    while (1);
//  }

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

  // set advertised local name and service UUID:

  // add the characteristic to the service

  // add service

  // assign event handlers for characteristic
  SliderCharacteristicHorizontal.setEventHandler(BLEWritten, SliderCharacteristicHorizontalWritten);
  SliderCharacteristicVertical.setEventHandler(BLEWritten, SliderCharacteristicVerticalWritten);

  // set the initial value for the characeristic:

  // start advertising

  Serial.println("BLE Peripheral Ready");

  //Start ticker for motor with 1ms
 //motor_ticker.attach_us(&step_motor, 100);


void loop() {


//      //Read IMU data and update angle
//      if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
//          IMU.readAcceleration(ax, ay, az);
//          IMU.readGyroscope(gx, gy, gz);
//      }

       Serial.print("slider value hor: ");
       Serial.print(" slider value ver: ");


void SliderCharacteristicHorizontalWritten(BLEDevice central, BLECharacteristic characteristic) {

          slidertest = SliderCharacteristicHorizontal.value();


void SliderCharacteristicVerticalWritten(BLEDevice central, BLECharacteristic characteristic) {
         slidertest2 = SliderCharacteristicVertical.value();

void step_motor()
       //Here is my motor code


I would recommend you reduce the number of BLE.poll() calls. Your BLE module may be stressed out. :slight_smile:

Did you write the app yourself? Is that complicated? Can you recommend any tutorials that help you write the app?

Thanks, will try - fingers crossed.

In respect to the app:

1 Like

Thanks for the tip! I ran it with a reduced number of polls (every 20ms).

-> It works perfectly fine on a Nano 33 BLE board and it always reads the correct values/ if I poll too often the connection crashes and requires a restart though

-> On the rp2040 it also seems to solve the issue that the connection crashed sometimes as well as the wrong numbers.

EDIT: Unfortunatelly even with the 20 ms delay i now and then read values which are not sent by my phone - occasionally. It seems to be caused by the timer (commented in code above). It works with the 33 BLE running the exact same code except for the IMU though.

Any ideas how to solve this? Maybe something like the noInterrupts() function?

Thanks a lot already!

The RP2040 and the Nano 33 BLE are quite different. The RP2040 has two processors that can try to access peripherals at the same. I do not know whether the second processor is used by the ArduinoBLE library.

BLE itself uses a 24-bit CRC for all packets which can detect multiple bit errors. So, it is unlikely the cause of your problem.

This will not be easy to debug without access to a debugger and all the signals.

I think the easiest cause of action for now is to implement application-level data checking.

It is still early days for this device. Maybe with more hour’s experience and more users developing with this Arduino we will have a better chance of figuring this out.

Thanks for your anwer!

I used two different timer libraries. Both cause the same issue. With the timer/ticker deactivated there is no issue anymore.

Nevertheless you handed the solution: i now use the second core to run my stepper motor, independently from what the other core is doing. Et voilĂ  - no BLE issues anymore :slight_smile:

For reference: Arduino Nano RP2040 Connect multicore

1 Like

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