Python script demonstrating the communication with Nuimo on a Raspberry Pi
The bluez library will be used to enable your Bluetooth dongle. It also provides tools to manually interact with Bluetooth Low Energy (BLE) devices.
sudo apt-get install --no-install-recommends bluetooth
(Installs bluez)sudo hciconfig hci0 up
(Enables your Bluetooth dongle)sudo hcitool lescan
(Should discover your Nuimo, press Ctrl+C to stop discovery)
sudo hcitool lescan | grep Nuimo
(Copy your Nuimo's MAC address and press Ctrl+C to stop discovery)sudo gatttool -b FA:48:12:00:CA:AC -t random -I
(Replace the MAC address with the address from step 1)connect
(Should successfully connect to Nuimo)characteristics
(Displays Nuimo's GATT characteristics)- Look for uuid
F29B1529-...
(button press characteristic) and note itschar value handle
(2nd column). Here:001d
. - Add
1
to the handle. Here:001d + 1 = 001e
(Hexadecimal value representation; use a calculator if necessary) char-write-req 001e 0100
(Registers for button click events; replace001e
with the handle from step 6)- Hold Nuimo's click button pressed and release it.
gatttool
should now notify all button press events. exit
to leavegatttool
The bluepy library is written in Python and will be used to communicate with your Bluetooth dongle in Python scripts.
From your home folder do:
sudo apt-get install build-essential libglib2.0-dev libdbus-1-dev python-setuptools git
(Installs build dependencies and git)sudo pip install -U pip
(Upgrade Pip to latest version)sudo pip install https://github.com/IanHarvey/bluepy/archive/master.zip#bluepy
From your home folder do:
wget https://raw.githubusercontent.com/getsenic/nuimo-raspberrypi-demo/master/nuimo-bluepy/__init__.py -O nuimo.py
(Downloadsnuimo.py
)nano nuimo.py
(If you want to modify the Nuimo demo script, Ctrl+X to quitnano
)
From your home folder do:
sudo hcitool lescan | grep Nuimo
(Copy your Nuimo's MAC address and press Ctrl+C to stop discovery)python nuimo.py FA:48:12:00:CA:AC
(Replace the MAC address with the address from step 1)- Perform input events on your Nuimo, they will show up on your console
- If you are having trouble to connect your Raspberry Pi to your computer or your router, refer to the Raspberry Pi ASAP Setup Guide
- If
sudo hcitool lescan
printsSet scan parameters failed: Input/output error.
, try running the following commands:
sudo hciconfig hci0 down
sudo hciconfig hci0 up
If you have questions or comments, please visit https://senic.com/developers or shoot us an email to developers@senic.com.