Bluetooth Low Energy (BLE) Tutorial for Beaglebone
by bleuio in Circuits > Computers
14 Views, 0 Favorites, 0 Comments
Bluetooth Low Energy (BLE) Tutorial for Beaglebone
Introduction
This is a simple example showcasing how to control a BleuIO dongle connected to Beaglebone Black using a python script.
When running the script, it will first ask for the com port where the dongle is connected (usually ‘/dev/ttyACM0’). After that, the BleuIO will start advertising. Every 8th second it will turn on one of the onboard Beaglebone Black LEDs whilst changing the BLE advertising name to indicate which LED is on.
Supplies
A ComputerA BleuIO dongle (https://www.bleuio.com/)
A BeagleBone Black (https://beagleboard.org/black) with Beaglebone Firmware installed (https://beagleboard.org/latest-images)
About the Code
You can get access to the project HERE
https://github.com/smart-sensor-devices-ab/beagleb...
We are using the Linux debian image: ‘OMAP3/DM3730 Debian 9.5 2018-10-07 4GB SD LXQT’ (https://beagleboard.org/latest-images).
We are using the Adafruit_BBIO python library that comes with the Beaglebone to control the onboard LEDs. First we define the LEDs names and then set them as GPIO Outputs. Then we define the advertising messages that the BleuIO will switch between. Lets break one down:
“10:09:42:6C:65:75:49:4F:20:4C:45:44:20:30:20:4F:4E:”
“10” is the size of the advertising packet in HEX.
“09” is the flag for device name (Complete Local Name).
“42:6C:65:75:49:4F:20:4C:45:44:20:30:20:4F:4E” is the packet itself, translated from HEX to ASCII it says: “BleuIO LED 0 ON”
Afterwards the user is presented with a message to input the com port the BleuIO is connected to. If you are not using a USB Hub the port should be ‘/dev/ttyACM0’.
You can change the comport name in the Python script and fill in your COM port.
com_input = "/dev/ttyACM0"
The script continues into the main loop, where it will first make sure all LEDs are off and then start BLE advertising.
The loop iterates through all four LEDs. In every iteration it turns one LED on and advertise the LED name then continue to the next LED. This will continue until the script is aborted.
How to Setup Project
Downloading the project from GitHub
Get access to the project HERE
https://github.com/smart-sensor-devices-ab/beagleb...
clone the project, or download it as a zip file and unzip it, into a folder on your BeagleBone.
You can also create a new python file using the Cloud9 IDE from the BeagleBone (run by going to http://192.168.7.2:3000/).
Copy the code and pasting it into the newly created file.
Installing pyserial
To run the script you will need to install the python library pyserial.
The easiest way of doing this is just connecting to the BeagleBone via shh (the default password is temppwd):
or using the bash tab in the Cloud9 IDE and type:
sudo pip3 install pyserial