Project Big Button

Overview

Exchanging data between a number of Bluetooth Low Energy devices/sensors from a Linux hub is something that could be
useful for a number of use cases.

As I’ve been learning Bluetooth on Linux using Python I’ve been looking for a fun way to demonstrate the above
functionality. Then I remembered about the buttonFlash game
that Albert Hickey had built and shown at a community
event in Cambridge. He had used WiFi with esp8266 in Pringles tubes.

I thought this game was a good candidate to do with Bluetooth. I had originally intended to also use Pringles
tubes and then I saw the 100mm buttons which were too big for Pringles tubes.
I settled on using the micro:bit as my Bluetooth peripheral as it has a very well defined BLE profile and
predefined code from Martin Woolley so I could focus on the Python code on the Dragonboard 410c.

Setting Up The micro:bit

Thanks to Bitty Software this is very easy as they have done a hex file for the micro:bit that exposes all of the
Bluetooth services we need. This was created for their micro:bit blue app (you should check the app out as it is
very
good). You can download the hex file from their webiste.

You will need to look for "Main Bluetooth services, pairing not required" link for the download. The loading of the
hex
file is standard for the micro:bit. We have chosen ‘pairing not required’ option because for this exercise we value
simplicity more than security.

The first time you start the micro:bit with this hex file it will be requested to draw a circle. This is to calibrate
the magnetometer. Once calibration is done you are good to use the micro:bit.

Setting Up the Dragonboard 410c

This is a little bit more involved as at the time of writing this Debian Jessie comes with BlueZ (the Linux Bluetooth
stack) version 5.23.

We are going to access BlueZ through its D-Bus GATT API which was released to production in version 5.43.
So we need to upgrade the version of BlueZ.
There are full instruction on how to perform the upgrade available in the Bluezero repository at:

Bluetooth Low Energy

Bluetooth and even just BLE is a very big topic that is too large to be covered in this article. The key piece of BLE
(for this project) is the Generic Attribute Profile (GATT) which is used to store Services, Characteristics and
related
data in a simple lookup table using 16-bit UUIDs for each entry in the table.

Characteristics are defined attribute types that contain a single logical value which is what we are going to focus
on.

D-Bus

The BlueZ API makes use of the D-Bus software bus, to communicate between your program and the Bluetooth daemon. This
article will not attempt to explain D-Bus. Hopefully it will be enough to say the Bluetooth information used by
BlueZ on
linux has a directory looking structure that reflects the Bluetooth GATT database. It is this D-Bus object path that
is
used as input for pydbus.

We have created a Python function called get_dbus_path that helps us get the D-Bus object path for known Bluetooth
GATT
UUID’s

This diagram shows how the adapter, device, service, characteristic and descriptor build to make the D-Bus object
path

What next

The ‘button box’ is functioning very well and now it has been built more possibilities are presenting themselves. For
example, the LED display is clearly visible through the box and could be used to convey information.

For example the buttons could be used as a quiz buzzer and the LEDs could be used to display that teams score.

Demo

I got invited along to London Open Hardware to demo this project. See how it went...