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

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:

lsusb
Bus 003 Device 008: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

sudo hciconfig -a hci0 features
hci0:	Type: BR/EDR  Bus: USB
	BD Address: 00:15:83:64:BA:E9  ACL MTU: 310:10  SCO MTU: 64:8
	Features page 0: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
		3-slot packets, 5-slot packets, encryption, slot offset,
		timing accuracy, role switch, hold mode, sniff mode, 
		park state, RSSI, channel quality, SCO link, HV2 packets, 
		HV3 packets, u-law log, A-law log, CVSD, paging scheme, 
		power control, transparent SCO, broadcast encrypt, 
		EDR ACL 2 Mbps, EDR ACL 3 Mbps, enhanced iscan,
		interlaced iscan, interlaced pscan, inquiry with RSSI,
		extended SCO, EV4 packets, EV5 packets, AFH cap. slave
		AFH class. slave, LE support, 3-slot EDR ACL,
		5-slot EDR ACL, sniff subrating, ,pause encryption,
		AFH cap. master, AFH class. master, EDR eSCO 2 Mbps,
		EDR eSCO 3 Mbps, 3-slot EDR eSCO, extended inquiry,
		LE and BR/EDR, simple pairing, encapsulated PDU, 
		non-flush flag, LSTO, inquiry TX power, EPC 
		extended features 
	Features page 1: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00

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:

# Base this image on rpi-hwup-image 
include rpi-hwup-image.bb

IMAGE_FEATURES += "ssh-server-dropbear"
IMAGE_INSTALL += "bluez4 libical"

and built the new image starting from poky directory:

. oe-init-build-env build
bitbake rpi-ble-image

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:

wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.7.tar.xz
tar xvf bluez-5.7.tar.xz
cd bluez-5.7
sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev automake libudev-dev libical-dev libreadline-dev
./configure --disable-systemd
make
sudo make install
sudo cp attrib/gatttool /usr/local/bin/

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:

export PATH=$PATH:/home/jaufranc/edev/rpi/yocto/poky/build/tmp/sysroots/x86_64-linux/usr/bin/armv6-vfp-poky-linux-gnueabi/

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:

hciconfig hci0 up

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

hcitool lescan
LE Scan ...
BC:6A:29:AC:1A:5F (unknown)
BC:6A:29:AC:1A:5F 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:

gatttool -b BC:6A:29:AC:1A:5F --interactive
[ ][BC:6A:29:AC:1A:5F][LE]> connect
[CON][BC:6A:29:AC:1A:5F][LE]> char-write-cmd 0x29 01
[CON][BC:6A:29:AC:1A:5F][LE]> char-read-hnd 0x25
[CON][BC:6A:29:AC:1A:5F][LE]>
Characteristic value/descriptor: a7 ff fc 0e
[CON][BC:6A:29:AC:1A:5F][LE]> char-write-cmd 0x26 0100
[CON][BC:6A:29:AC:1A:5F][LE]>
Notification handle = 0x0025 value: a3 ff 08 0f
[CON][BC:6A:29:AC:1A:5F][LE]>
Notification handle = 0x0025 value: aa ff 08 0f
[CON][BC:6A:29:AC:1A:5F][LE]>
Notification handle = 0x0025 value: a9 ff 08 0f
[CON][BC:6A:29:AC:1A:5F][LE]> char-write-cmd 0x26 0000
[CON][BC:6A:29:AC:1A:5F][LE]> exit

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

Type UUID Handle Read/Write Format
<Data> F000AA01 * 0x25 Read/Notify ObjLSB ObjMSB AmbLSB AmbMSB (4 bytes)
<Data Notification> 0x26 R/W 2 bytes
<Configuration> F000AA02 * 0x29 R/W 1 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.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. Paul
    December 22nd, 2013 at 06:35 | #1

    Finally found time to play with my SensorTag…

    I don’t know where requirement for kernel 3.5 comes from, 3.2.0 as used in Ubunru 12.04LTS works fine. But shipped bluez package (4.98-2ubuntu7) is indeed too old, I was getting:

    root@x34f:~# gatttool -i hci1 -b BC:6A:29:AB:E9:C6 –interactive
    [ ][BC:6A:29:AB:E9:C6][LE]> connect
    connect: No route to host (113)

    So, I built latest (5.12) from source, and then it worked fine.

    Jean-Luc, did you play with it further? I’m interested to know if BLE battery life lives anyhow to promise ;-). And any thoughts on working distance? My initial testing shows rather mediocre range, it loses connection at 4m distance with 1 wall inbetween brick, hardly even concrete. Still worked at 2m with the same wall. The only good news is that it’s pretty consistent with what I saw for other 0dBm 2.4GHz modules with PCB antenna, so at least can’t blame cheap Chinese modules, only 2.4GHz and physics ;-).

  2. December 22nd, 2013 at 09:23 | #2

    @Paul
    No I did not play further. One other person left a comment about the difficulty to change the firmware however, because you need to buy a $3K tool, after the 30-day trial period.

    http://www.cnx-software.com/2013/05/31/25-texas-instruments-sensortag-is-a-bluetooth-le-devkit-with-6-sensors/#comment-129343

    It seems BLE was there, but not enabled by default before kernel 3.5 – http://www.spinics.net/lists/linux-bluetooth/msg24480.html
    This presentation also mentions this together with improvement in 3.6. – http://elinux.org/images/1/1b/Bluetooth_Smart_devices_and_Low_Energy_support_on_Linux.pdf

  3. Paul
    December 23rd, 2013 at 03:02 | #3

    @cnxsoft

    Thanks for response. Regarding firmware hacking, I guess the biggest question is who on Earth would like to hack with 8051 in 2014 ;-). But if some will want, it’s all doable, for example, Contiki was ported to previous TI 8051 chips using SDCC: https://github.com/adamdunkels/contiki-fork/wiki/8051-Based-Platforms .

  4. December 23rd, 2013 at 09:34 | #4

    @Paul
    SensorTag is only discoverable 180 seconds after pressing the button, so people have wanted to change that to be discoverable for longer intervals, or at specific times. For a weather station for example, it’s not that convenient to walk outside, and press the button to get the data….

  5. Paul
    December 23rd, 2013 at 13:14 | #5

    @cnxsoft

    Btw, with wanting to do that specific change, my guess is that people miss with understanding what BLE is and how it works. “Discoverable” means it sends advertisements at rather short intervals (TI says SensorTag does 100ms for example), which in turn means in burns battery. An accessory won’t deliver “years on single coin cell”, likely just days. The way BLE should be used is that you discover devices, connect to it, and then query it infrequently.

    If people just want to burn battery, they don’t need to abuse BLE for that, classic BT is enough. For example, when hacking on HC-04 and https://github.com/pfalcon/blutunode , I couldn’t get below 2mA (no public datasheets on low-power config of BlueCore4 chips), I stopped worked on it due to that, but some people might be just happy.

    Re: “weather station” example: as you remember, I initially asked for impressions on range. IMHO, “outside” scenario not going to work with BLE at all. It seems that it reliably can work only within a room, single wall is a challenge.

  6. Pat
    April 2nd, 2014 at 23:01 | #6

    you wouldn’t happen to know if you can get one of the above usb dongles working and communicating in linux 2.6/3.x android 4.3 iso in virtualbox on Win 7 ? I tried a bluegiga bled112 (thinking any would do) and I can see the device connected to the vm but in android bluetooth won’t start. It almost immediately switches off when you switch it on. any ideas or suggestions would be great as I’m planning to return the bluegiga. thx

  7. April 21st, 2014 at 02:45 | #7

    Hi guys,

    we created our own firmware which disables the sleep mode. It works pretty well! If you are interested, have a look here – we have written a guide how it can be downloaded and installed easily:
    http://www.myweathercenter.net/faq/

    We use the firmware for our iPhone App MyWeatherCenter, which was featured by Apple these days.

    With MyWeatherCenter you can create a beautiful Weatherstation that shows you the latest weather sensor data from the TI SensorTag. If you want to try it, just download it here:
    https://itunes.apple.com/de/app/my-weather-center/id824900305?ls=1&mt=8

    We would be happy to receive your feedback about it!

    Best regards,
    Oliver

  8. Tõnu Samuel
    August 8th, 2014 at 20:34 | #8

    @Oliver Heinrich “Just download” is not appropriate for paid app.

  9. Yaqz
    October 9th, 2014 at 19:05 | #9

    Awesome topic, ..When trying to connect to Sensor tag, I used to have error: connection host down (112). This line of code “”cp attrib/gatttool ../bluez/bin/”” got me this new message “Attempting to connect to MacAdress”.

    I can tell “”cp attrib/gatttool ../bluez/bin/”” changed the situation because I had already had the newest version of Bluez and did all the steps mentioned previously of installation.

    Now I would be p-leased if you explain to me why and what does that code stands for ?

  1. July 22nd, 2013 at 00:02 | #1
  2. July 30th, 2013 at 17:40 | #2
  3. May 6th, 2014 at 10:33 | #3
  4. September 1st, 2014 at 11:50 | #4