Texas Instruments SensorTag Unboxing, Getting Started with Bluetooth Low Energy in Linux (with a Raspberry Pi)

Texas Instruments CC2541 SensorTag is a Bluetooth Low Energy (BLE) development kit with 6 sensors (IR temperature, humidity, pressure, accelerometer, gyroscope, magnetometer) mainly destined at mobile application developers for iOS, and soon, Android 4.3. I’m interested in BLE, as I expect most new phones with come with BT 4.0 BLE (aka Bluetooth SMART), and this technology may help bring the Internet of things to life, allowing us to interact with sensors, smart appliance (e.g. light switch)… Since it just costs $25 (including international shipping), I decided to buy it, and give it a try. Today, I’ll show some unboxing pictures, and how to communicate with the kit using the Linux command line.

TI SensorTag Unboxing

I ordered it at the end of May, and receive it by Fedex on the 18th of July, about 7 weeks later, in the package below.

Texas_instruments_CC2541_SensorTag_Development_Kit_Package

Inside we’ve got a Quick Start Guide for iOS and Windows, a screw for the enclosure, CC2541 SensorTag board, 2 parts for the enclosure, and a CR2032 battery.

(Click to Enlarge)
(Click to Enlarge)

There are also some documents with warning, and legalese, mainly explaining this kit is only for development. On another important info is that in Japan, you can only use this kit in a shielded room or specialized test facility, or you may get into troubles with the authorities.

TI_SensorTag_Board_640px
(Click to Enlarge)

On one side of the board (left on pic), we’ve got the battery socket,S1 button to turn on/off the SensorTag,  the humidity sensor (U6, Sensirion SHT21),  and TI CC2541 Bluetooth low energy SoC. J1 connector is used to debug, and flash CC2541.

On the other side, we’ve got S2 & S3 push-buttons, a pressure sensor (U4 , Epcos T5400), an infrared thermopile sensor (U5, TI TMP0006), a magnetometer (U3, Freescale MAG3110), an accelerometer (U7, Kionix KXTJ9), and a gyroscope (U8, InvenSense IMU-3000).

You can also watch SensorTag Unboxing Video if you please.

Assembly of the SensorTag

Assembling the SensorTag is pretty easy. First insert the CR2032 battery, and press S1 to check the connection is fine, as it should make D1 blink. If it does not work, you may have to remove and re-insert the battery a few times (I did not have to do this). Place the PCB in the black plastic cover, fastened the PCB with the screw, and add the transparent plastic cover.
TI_SensorTag_Assembly

Complete the assembly by adding the red plastic cover.
TI_SensorTag

Getting Started with SensorTag / Bluetooth Low Energy in Linux

Since I don’t own an iOS device, my only option is to use a computer running Windows or Linux. In that case, we need USB dongle supporting Bluetooth 4.0 Low Energy. I bought a dongle called BD-401 for $5.25 on Ebay, but the listing is now gone, and it was also on DealExtreme, but for some reasons it seems to have almost completely disappeared from the web, and I can only find it in one Aliexpress store for $7. Here are some of the USB dongle technical details for your reference:


Another option is to buy Plugable USB-BT4LE on Amazon for about $15.

If you want to use SensorTag with a Windows computer, you’ll need to download and install BLE Device Monitor. TI clearly mentions you need CC2540 USB dongle ($49) to use the software, but I just thought any BT 4.0 BLE dongle might do. When I saw BLE Device Monitor looking for a COM port, I knew this was not going to work, and you indeed need TI kit, and install a specific firmware on the dongle.

Luckily this is not the case in Linux. The requirement is just to have Linux 3.5, the first kernel version with Bluetooth Low Energy support, or better Linux 3.6 which adds some improvements. Since I had a Raspberry Pi on my table running Linux 3.6.11, and somebody clever already provided instructions to use SensorTag with the board, I decided to use this platform for playing around. Instructions for the BeagleBone Black are also avauilable, but the link not currently working.

You’ll need a recent version of Bluez, an open source Bluetooth library, in order to support BLE devices such as the SensorTag, and I’ll provide three methods to build it.

Since I’ve recently used Yocto to build Linux for the Raspberry Pi, I’ve created a new image recipe in meta-raspberrypi/recipes-core/images/rpi-ble-image.bb:


and built the new image starting from poky directory:


A few minutes later, I’ve got an 88MB SD card image (./tmp/deploy/images/rpi-ble-image-raspberrypi.rpi-sdimg) with all tools (hcitool and gatttool) required to play with my SensorTag. That was easy.

Yocto provides Bluez 4.4 in this build, and it works fine with my system, but the latest version is 5.7, so you could also build the library and the tools natively in a Raspberry Pi:


The other method is to cross-compile the library. The build is not too complex and long, and this should not really be needed, unless you use a small SD card (like I do). You’ll need an ARM cross-toolchain, and since I’ve got the ARMv6 toolchain for Raspberry Pi built with Yocto, I’ll add it to my path in ~/.bahrc:


One the side note, the right way to do with yocto, would probably be edit the recipe in meta/recipes-connectivity/bluez/ to update the version. It seemed complicated, so I passed.

Let’s cross-compile Bluez for ARM, and install it in ../bluez in a Linux computer:

mkdir sensortag
cd sensortag/
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.7.tar.xz
tar xvf bluez-5.7.tar.xz
USB_CFLAGS="-I/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/raspberrypi/usr/include" USB_LIBS="-L/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/raspberrypi/lib -lusb" UDEV_CFLAGS=$USB_CFLAGS UDEV_LIBS="-L/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/raspberrypi/usr/lib -ludev" ICAL_CFLAGS=$USB_CFLAGS ICAL_LIBS="-L/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/raspberrypi/usr/lib -lical" ./configure --target=arm-poky-linux-gnueabi- --host=arm-poky-linux-gnueabi --prefix=/home/jaufranc/edev/rpi/sensortag/bluez --disable-systemd --disable-obex --disable-datafiles --disable-udev --with-sysroot=/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/raspberrypi/
make
make install
cp attrib/gatttool ../bluez/bin/

Finally, you just have to copy all files in ../bluez directory to the Raspberry Pi using an NFS share.

I’ve just use the first method (Image built with Yocto) to test the SensorTag.

First, we need to enable hci0 interface:


Now, let’s try to find the SensorTag, by running the command line below, and pressing S1 button on the side of the SensorTag:


Great we’ve found it! This command will continuously scan for devices, so press control-C to stop it.

Please note that SensorTag will turn itself off automatically if it is not connected, so you may have to press S1 again.

Gatttool allows us to connect to the kit, manually write commands, and read data:


We are querying the temperature sensor (U5) with handles from the following table:

TypeUUIDHandleRead/WriteFormat
<Data>F000AA01 *0x25Read/NotifyObjLSB ObjMSB AmbLSB AmbMSB (4 bytes)
<Data Notification>0x26R/W2 bytes
<Configuration>F000AA02 *0x29R/W1 byte

Obj is the object temperature, and Amb, the ambient temperature.

The first command “char-write-cmd 0x29 01” enables the temperature sensor (all sensors are disabled by default to preserve energy). The second command (0x25) reads the sensor temperature. “char-write-cmd 0x26 0100” makes the device send temperature reading continuously (e.g. every seconds), and “char-write-cmd 0x26 0000” stops that.

Visit http://processors.wiki.ti.com/index.php/SensorTag_User_Guide#Gatt_Server for detailed explanations for all sensors, and algorithms to derive usable values.

If you want to write you own program, you can probably do so by starting from gatttool source code (C language) located in attrib directory of Bluez library. Mike Saunby, who provided the instructions for the Raspberry Pi, also wrote a program in python calling gatttool to retrieve the data, as well as a NodeJS / socket.IO web app to display temperature and accelerometer values in real-time in a web browser. His code is available on github.

Support CNX Software - Donate via PayPal or cryptocurrencies, become a Patron on Patreon, or buy review samples
Subscribe
Notify of
guest
13 Comments
oldest
newest most voted
Advertisements