Copyrights 2020-2024 Embedded AMS B.V. Amsterdam, www.EmbeddedAMS.nl, info@EmbeddedAMS.nl
Looking for a more elaborate description of this example? Please visit: https://embeddedproto.com/ble-example-with-embedded-proto/
This repository hosts example code for Embedded Proto, the embedded implementation of Google Protocol Buffers. It is a simple example showing how a microcontroller and desktop pc can communicate using Bluetooth Low Energy (BLE). Command messages are send from a desktop script to the MCU using BLE.
This example uses BLE to control a led on the NUCLEO board and also retrieve a sensor value. We use of a NUCLEO-F446RE and a X-NUCLEO-IDB05A1 bluetooth evaluation board both made by ST Microelectronics. The microcontroller is based on an ARM Cortex-M4 processor. To build the source code and program the hardware STM32CubeIDE has been used.
The desktop program is a simple python script. From this script you can turn on/off the led on the NUCLEO board, and also retrieve a random value from an emulated sensor.
- Install STM32CubeIDE if you have not already.
- Install the dependencies required by Embedded Proto. They are listed here, please match the version used in this example.
- Checkout this example repository including the submodule of Embedded Proto:
git clone --recursive https://github.com/Embedded-AMS/EmbeddedProto_Example_STM32_BLE.git
. - Setup the environment required for Embedded Proto and the desktop script by running the setup script:
python ./setup.py
.
The setup script already does it for you but you can regenerate the source code using the ./generate_source_files.sh
or generate_source_files.bat
script. This is required when you have changed the *.proto file.
First connect the BLE X-NUCLEO-IDB05A1 to the NUCLEO. Then connect the NUCLEO via the usb programmer and use STM32CubeIDE to build and program the microcontroller on it.
Next go to the desktop folder, activate the virtual environment and run the script.
On Linux:
cd desktop
source venv/bin/activate
python3 main.py
On windows
cd desktop
.\venv\Scripts\activate
python main.py
Have fun!