BLE Arduino ESP32 - which library should I use?

I'm starting a project : read an ADC value on ESP32 (peripheral) and send it over BLE to android (central). I'm a bit confused looking for proper libraries . I found at least 3 solutions/libraries

1: #include <Adafruit_BluefruitLE_SPI.h>

2: #include <BLEDevice.h>
   #include <BLEServer.h>
   #include <BLEUtils.h>
   #include <BLE2902.h>
3: #include <ArduinoBLE.h>

It looks like the 3'rd one is most modern and officially published by Arduino IDE (see the link GitHub - nkolban/ESP32_BLE_Arduino at adc2aee2f0d01eb6b30dd5ad3589f2cc89934beb ), hence 2 has more examples then others.

Using 2 I can use .notify command to start publishing the value. Using 3 there is no documentation for this command, it looks like I should only use .writeValue and the .poll is taking care of publishing the value.Also 3 is using setEventHandler , while 1 and 2 don't have this described.
Is it right to use 3 because it is officially published by Arduino IDE and has full documentation within Ardiuno IDE ?

1 Like

I think you must use option 2. I doubt the libraries are compatible but I have not tried it myself. I used option 2 with my ESP32 board and option 3 with Arduino Nano 33 BLE, IoT and RP2040 Connect.

I agree. I found the ArduinoBLE library to be the easiest to understand and use.

With the ArduinoBLE library you simply declare a characteristic with notification. e.g.,

BLEUnsignedCharCharacteristic batteryLevelChar("2A19", BLERead | BLENotify);

Everything else is taking care of by the library. No need for a separate header file, you do not need to add the descriptor and you do not need to call notify when you write the characteristic.

As I said, I do not believe that would work with ESP32. I could be wrong.

You can see the documentation for the ArduinoBLE library here:

This library supports all the Arduino boards that have the hardware enabled for BLE and Bluetooth 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010.

This library is intended to provide BLE support for the official Arduino boards that have such a capability. Even though the ESP32 is the microcontroller that provides the BLE radio capability on the official boards with the NINA-W102 module (e.g., MKR WiFi 1010, Nano 33 IoT, Nano RP2040 Connect), the library code does not run on the ESP32, but instead of the primary microcontroller (e.g., ATSAMD21G18, RP2040). So there is not official support of this library for the ESP32. However, the Arduino community is not to be underestimated, and I notice that someone has a fork of the library that is claimed to have ESP32 support added:

I haven't tried it, so no idea whether it works or not, but certainly worth a look!


OK, it seems to work. Here is what I tested.

  • Download the ArduinoBLE library from the link above, unzipped and copied the folder to my projects library folder, renaming it to ArduinoBLE
  • Compiled with the ESP32 version 1.0.6 (got a compilation error)
  • added the development release link to File -> Preferences ->Additional Boards Manager

More details here:

  • in the Boards Manager installed ESP32 version 2.0.0-rc1
  • compiled again and programmed an ESP32-WROOM-32E

My example has an environmental sensing service, some characteristics with READ and Notify and additional descriptors. There was no code modification necessary for my Arduino example and everything works as expected.

@pert Thank you for the link.


ArduinoBLE.h works fine. You can find a nice example code here.. I've never used it with ESP32 though.

It seems that only @2 is designed for ESP32 module. It's quite popular, for ESP32 it won't be a bad choice. olehana portugal

1 Like

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