RPi Bluetooth LE

= Bluetooth LE on the Raspberry Pi =

At the time of writing Bluetooth Low Energy (BLE) is not well supported by the standard Raspberry Pi distributions. Some work is required to get it working, as described below.

Software
This page has been tested using the Raspbian Wheezy distribution, in particular the image at: http://downloads.raspberrypi.org/raspbian/images/raspbian-2014-01-09/2014-01-07-wheezy-raspbian.zip

For reference, uname -a on the test system returned: Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux

Hardware
You will need a Bluetooth 4.0 compatible USB adapter to use with the Pi. The following devices have been tested:
 * Plugable USB-BT4LE adapter: http://plugable.com/products/usb-bt4le (uses BCM20702 chipset)
 * CSR chipset adapter http://www.amazon.co.uk/Version-Bluetooth-Adapter-Compatible-Windows/dp/B00A0CBOTE

BlueZ installation
By default, the Wheezy distribution comes without a Bluetooth stack. The bluez package is version 4.99, which has patchy support for Low Energy. You can build and install a more modern version as follows:

BlueZ 5.4 build instructions
Firstly, you'll need a download and install a number of development libraries. From a command prompt run: sudo apt-get install libdbus-1-dev libglib2.0-dev libdbus-glib-1-dev sudo apt-get install libusb-dev libudev-dev libreadline-dev

Then, download the source: mkdir -p work/bluepy cd work/bluepy wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.4.tar.xz xz -d bluez-5.4.tar.xz tar xvf bluez-5.4

If successful, you'll now have a bluez-5.4 source code directory on disk. To build it, do: cd bluez-5.4 ./configure --disable-systemd make

This will take half an hour or so. When this is done, do: sudo make install

USB Checks
To ensure the USB Bluetooth device is being seen, run lsusb

With the Plugable adapter shown above, the result will be similar to this: Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp.

The adapter is the one on Bus 001 Device 004. To show more information about the 'Broadcom' device, do: sudo lsusb -v -d 0a5c:

Using hcitool
If this is working, run the hciconfig tool: pi@raspberrypi ~ $ hciconfig hci0:	Type: BR/EDR Bus: USB BD Address: 00:02:72:14:27:0E ACL MTU: 1021:8  SCO MTU: 64:1 DOWN RX bytes:2715 acl:1 sco:0 events:146 errors:0 TX bytes:2500 acl:0 sco:0 commands:133 errors:0

If the bluetooth adapter (hci0 in the above example) is down as DOWN, you will need to enable it with: sudo hciconfig hci0 up

Scanning for LE devices
If you have any Bluetooth LE devices, you can start scanning for them with: sudo hcitool lescan

For the TI SensorTag, pressing the button on the side will ensure the device is awake and broadcasting advertising packets. Other LE devices may need a similar action - please consult the relevant user manual.

Links: other Bluetooth Low Energy resources

 * http://www.bluez.org/ - BlueZ stack announcements and downloads
 * https://www.bluetooth.org/en-us/specification/adopted-specifications - Bluetooth official specifications
 * -> Index of assigned numbers