create new tag
view all tags

BlueTooth Low Energy (BLE)

The ESP32 provides a BlueTooth interface and MicroPython implements a low level interface tto BlueTooth Low Energy or BLE.

Some applications may prefer using BLE instead of WiFi for their commnunication with the outside world and you may want to port applications written for other processors that only support BLE.

I found this YouTube video, demonstrating how to communicate between an ESP32 and a smart phone using a serial BLE protocol ( Nordic UART Service NUS). It uses the user LED and the GPIO-0 button, used be some CPU boards to put the ESP32 into flash programming mode. If not used for flash programming the button can be used by any program. Unfortunately I could not find the program source any longer and I therefore decided to re-create it myself. You can find the source code here: https://github.com/uraich/IoT-Course/tree/master/exercises/solutions/exercise_22

For experiments with TinyML I bought an ESP32-S3FH4R2 CPU board, which has both, the GPIO-0 button as well as the user LED, which however is implemented as a ws2812 neopixel rgb LED.


As you can see on the photo, the ws2812 is connected to GPIO-47.

The program advertises the NUS service and waits for connections. In this state it flashes the LED at high frequeny ( 10 Hz) .You can use Serial BlueTooth app to connect to it. As soon as the BLE central has connected the LED switched to steady on. Now you can read the LED state from the BLE terminal with the command: read_LED. If the button is pressed, the LED toggles its state and the BLE terminal gets the notification message: LED state will be toggled.

The result

The BLE program on the ESP32 can be accessed through the BLE terminal app on the smart phone.

ble_devices.png ble_communication.png
The device is discovered The communication
On the ESP32, this is what we see:
The black text is the log from the ESP32, the blue text has been added for explication later.


Running a BLE terminal on the PC

In order to run a BLE terminal on the PC several steps are needed:

  • ble-serial must be installed on a Python virtual environment
  • you must run ble-scan to check that the ESP32 BLE program is detected
  • you must run ble-serial and find the BLE MAC address. This will connect the BLE serial protocol onto a /dev/pts/x terminal (x must be replaced by the number indicated)
  • finallly run minicom on the pts device and set local echo on (<ctrl> a E)


-- Uli Raich - 2023-10-30


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng ble-serial.png r1 manage 100.2 K 2023-10-30 - 11:02 UliRaich  
JPEGjpg ble_communication.jpg r1 manage 225.3 K 2023-10-30 - 10:00 UliRaich  
PNGpng ble_communication.png r1 manage 29.2 K 2023-10-30 - 10:42 UliRaich  
JPEGjpg ble_devices.jpg r1 manage 128.6 K 2023-10-30 - 10:00 UliRaich  
PNGpng ble_devices.png r1 manage 22.8 K 2023-10-30 - 10:42 UliRaich  
PNGpng ble_minicom.png r1 manage 30.6 K 2023-10-30 - 11:02 UliRaich  
PNGpng esp32_log.png r1 manage 61.2 K 2023-10-30 - 11:09 UliRaich  
PNGpng esp32s3_cpu.png r1 manage 283.9 K 2023-10-30 - 09:36 UliRaich  
Topic revision: r1 - 2023-10-30 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback