Difference: BLE ( vs. 1)

Revision 12023-10-30 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WebHome"

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.

esp32s3_cpu.png

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.

esp32_log.png

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)
ble-serial.png

ble_minicom.png

-- Uli Raich - 2023-10-30

Comments


<--/commentPlugin-->

META FILEATTACHMENT attachment="esp32s3_cpu.png" attr="" comment="" date="1698658616" name="esp32s3_cpu.png" path="esp32s3_cpu.png" size="290745" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble_communication.jpg" attr="" comment="" date="1698660001" name="ble_communication.jpg" path="ble_communication.jpg" size="230754" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble_devices.jpg" attr="" comment="" date="1698660001" name="ble_devices.jpg" path="ble_devices.jpg" size="131691" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble_communication.png" attr="" comment="" date="1698662527" name="ble_communication.png" path="ble_communication.png" size="29876" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble_devices.png" attr="" comment="" date="1698662527" name="ble_devices.png" path="ble_devices.png" size="23363" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble-serial.png" attr="" comment="" date="1698663743" name="ble-serial.png" path="ble-serial.png" size="102593" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ble_minicom.png" attr="" comment="" date="1698663743" name="ble_minicom.png" path="ble_minicom.png" size="31324" user="UliRaich" version="1"
META FILEATTACHMENT attachment="esp32_log.png" attr="" comment="" date="1698664156" name="esp32_log.png" path="esp32_log.png" size="62644" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback