This is a repository for the ones interested in developing BLE COM with modules such as HM10 with their arduino or microprocessors (It works with a PIC32MX from MPLAB) . I found several sources but none of then was working on the first shot or it simply something was updated and it is no longer valid. More about BLE in this link from Adafruit.
This project sets up an Arduino to communicate with a Bluetooth Low Energy (BLE) HM-10 module using UART (serial communication). It uses the SoftwareSerial
library to create a virtual serial port, allowing AT commands to be sent to the module to change its configuration, such as its device name.
UARTBLEHM10.ino
: Arduino sketch source code.
- Arduino UNO (or compatible board)
- HM-10 BLE module
- Wiring:
- HM-10 TX → Arduino Pin 10
- HM-10 RX → Arduino Pin 11
- Library:
SoftwareSerial
(included with the Arduino IDE)
- Initializes two serial ports:
Serial
: USB communication with the serial monitor.SoftwareSerial
: Communication with the HM-10 module.
- Sends AT commands to the BLE module:
- Changes the module's name using the
AT+NAME
command.
- Changes the module's name using the
- Act as a terminal with the serial monitor of the ARDUINO IDE
- Connect the BLE module to the Arduino as described above.
- Upload the sketch to the Arduino.
- Open the Arduino IDE Serial Monitor at 9600 baud.
- Watch for responses from the BLE module.
- You can customize the name by editing this line and changing the boolean variable on top of the file:
String NAME = "AT+NAMEBT05-" + String(0) + String(1) + "\r\n";
Original code adapted from https://blog.espol.edu.ec/girni/hm-10-serial-con-arduino-a-pc/
Existing terminals are an easy way to check if the module is working. However, since I don't want to depend on external app providers, I found MIT APP INVENTOR or a PYTHON terminal more interesting for my students since they can customize and create their own interfaces. Please check the following alternatives.
I wrote here the ones that work for me:
- On Android:
- Pending to write.
- On IOS (More complicate to find):
- BLE Serial Tiny:I found it in this Hangar42 post with a link to a github where you can find the link to the app https://github.com/hoiberg/HM10-BluetoothSerial-iOS
- LightBlue or nRF Connect to learn about the UUID service and its characteristics.
After several trials, especially for IOS, I obtained a working code to test the UART communications using IOS and ANDROID systems.
The app looks like this (the screenshot is from an Iphone 15 Pro) and can be adapted depending on your application:
- Import the aia project to your MIT APP INVENTOR. Please, check that the 2 TextSize blocks for the list viewers are enabled (I don't know why they are disabled when the project is loaded.)
- Write IOS or ANDROID in the OS global variable
. This has been the most significant pain since IOS and ANDROID act differently in the connection and the send block structure.
- Click Connect/Ai Companion
- Open your Mit APP inventor app in your device
- Connect the BLE module to the Arduino or IoT device. It should be blinking.
- Scan for new devices and click the one you want to connect. It should appear like: "Selected "
- Click Connect. Once connected, it should appear "Connected to "
- You can write messages and click send or you can receive message
- To clear the list, click CLS
- To add/remove '\n' from the end of your string, click ENDL/NO ENDL.
- Pressing a message in the console will be copied to the string to send box.
https://iot.appinventor.mit.edu/iot/reference/bluetoothle
This project demonstrates how to use the Nordic Semiconductor (nRF) UART service with Python. It allows communication with a BLE (Bluetooth Low Energy) device using the UART service.
- Scans for BLE devices and connects to a specified device.
- Sends messages to the BLE device and receives responses.
- Handles disconnection events gracefully.
- Python 3.7 or higher
- A BLE device supporting the UART service (e.g., HM-10 module)
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
- On Windows:
.\venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- Install dependencies:
pip install bleak
- Run the script:
python uart_service.py
- When prompted, enter the BLE address of the device you want to connect to. If you know the address beforehand, you can set it in the BLE_ADDRESS variable in the script.
- Type messages into the terminal and press ENTER to send them to the BLE device. The BLE device's responses will be displayed in the terminal.
- To exit, press CTRL+C to force quit.
- UART_SERVICE_UUID: UUID of the UART service.
- UART_RX_CHAR_UUID: UUID of the RX characteristic.
- UART_TX_CHAR_UUID: UUID of the TX characteristic.
- BLE_ADDRESS: BLE address of the target device (leave empty for user input).
Original code adapted from hbldh/bleak. Documentation for the bleak library: https://bleak.readthedocs.io/