Bluetooth LE on BeagleBone Black with TI SensorTag

Picked up a SensorTag from TI recently and decided to see if I could get the BeagleBone Black (BBB) to SensorTag bbbinteract with it.  I started with this posting by Mike Saunby for the Raspberry Pi. Below are the steps I took to get my IOGEAR Bluetooth 4.0 USB Micro Adapter (GBU521) working on the latest Angstrom distribution for the BBB.

First step, edit

/var/lib/connman/settings

to enable bluetooth:

[global]
OfflineMode=false [Wired] Enable=true [WiFi] Enable=true [Bluetooth] Enable=false    <====== change to true

Shutdown the BBB, plug the IOGear adapter into the USB port, and boot the BBB.

# hcitool dev
Devices:
# hci config -a
hci0: Type: BR/EDR Bus: USB
         BD Address: 00:02:72:3E:7C:EB ACL MTU: 1021:8 SCO MTU: 64:1
         DOWN
          RX bytes:495 acl:0 sco:0 events:22 errors:0
          TX bytes:369 acl:0 sco:0 commands:22 errors:0
          Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0×87
           Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
           Link policy: RSWITCH SNIFF
           Link mode: SLAVE ACCEPT
# lsusb
Bus 001 Device 002: ID 0a5c:21e8 Broadcom Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
#hciconfig hci0 piscan                                      <—– See note blow labeled PISCAN
# hciconfig -a
hci0: Type: BR/EDR Bus: USB
         BD Address: 00:02:72:3E:7C:EB ACL MTU: 1021:8 SCO MTU: 64:1
         UP RUNNING PSCAN ISCAN
         RX bytes:996 acl:0 sco:0 events:45 errors:0
         TX bytes:742 acl:0 sco:0 commands:45 errors:0
         Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0×87
         Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
         Link policy: RSWITCH SNIFF
         Link mode: SLAVE ACCEPT
         Name: ‘BCM20702A’
         Class: 0×000000
         Service Classes: Unspecified
         Device Class: Miscellaneous,
         HCI Version: 4.0 (0×6) Revision: 0×1000
         LMP Version: 4.0 (0×6) Subversion: 0x220e
         Manufacturer: Broadcom Corporation (15)
# hcitool lescan
LE Scan …
90:59:AF:0A:A9:D8 (unknown)
90:59:AF:0A:A9:D8 SensorTag
(hit cntrl-C to exit)
# hcitool lecc 90:59:AF:0A:A9:D8
Connection handle 64

Now to tell the SensorTag to return some data:

# gatttool -b 90:59:AF:0A:A9:D8 –interactive
[ ][90:59:AF:0A:A9:D8][LE]> connect
[CON][90:59:AF:0A:A9:D8][LE]> char-read-hnd 0×25
[CON][90:59:AF:0A:A9:D8][LE]>
Characteristic value/descriptor: 00 00 00 00
[CON][90:59:AF:0A:A9:D8][LE]> char-write-cmd 0×29 01
[CON][90:59:AF:0A:A9:D8][LE]> char-read-hnd 0×25
[CON][90:59:AF:0A:A9:D8][LE]>
Characteristic value/descriptor: b7 ff a0 0c

 

At this point, everything is working!

I proceeded to use Mike’s code on github to test.  I started with sensorTag_test.py as it repeatedly gives the temperature – I had to download/install pexpect first:

 # wget http://pexpect.sourceforge.net/pexpect-2.3.tar.gz
 # tar xzf pexpect-2.3.tar.gz
 # cd pexpect-2.3
 # python ./setup.py install

Now I can run the test:

# python sensortag_test.py 90:59:AF:0A:A9:D8
Preparing to connect. You might need to press the side button…
27.49 C
30.26 C
29.07 C
28.05 C
27.76 C
27.89 C

Hurray – working!

You can continue with Mike’s python code that reads all the sensors.

Note:  there was no need to build a copy of gattool or to build bluez-5.2 unlike what Mike had to do for the Pi.

So it is a simple procedure with all the right info – but I was stumped on getting the BBB to recognize the bluetooth adapter until I came across this posting to edit /var/lib/connman/settings to enable bluetooth.

Here is the version of Angstrom all this worked on:

# uname -a
Linux 3.8.13 #1 SMP Tue Jun 18 02:11:09 EDT 2013 armv7l GNU/Linux

PISCAN note:

After a subsequent reboot of the BBB, I had to add a step:
# hcitool dev
DEVICES:
# hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:3E:7C:EB ACL MTU: 1021:8 SCO MTU: 64:1
DOWN
RX bytes:495 acl:0 sco:0 events:22 errors:0
TX bytes:369 acl:0 sco:0 commands:22 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0×87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
On the third line of the response, you see the word DOWN, so I did the following:
# hciconfig hci0 up
# hciconfig dev
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:3E:7C:EB ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:990 acl:0 sco:0 events:44 errors:0
TX bytes:738 acl:0 sco:0 commands:44 errors:0
Now notice UP RUNNING on the third line!
Continuing on:
# hciconfig hci0 piscan
# hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:3E:7C:EB ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN ISCAN
RX bytes:996 acl:0 sco:0 events:45 errors:0
TX bytes:742 acl:0 sco:0 commands:45 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0×87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: ‘BCM20702A’
Class: 0×000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.0 (0×6) Revision: 0×1000
LMP Version: 4.0 (0×6) Subversion: 0x220e
Manufacturer: Broadcom Corporation (15)
# hcitool lescan
LE Scan …
90:59:AF:0A:A9:D8 (unknown)
90:59:AF:0A:A9:D8 SensorTag
cntrl+c
# hcitool lecc 90:59:AF:0A:A9:D8
Connection handle 64

Then I went back to the flow above…

Other posts leveraged:

http://ferryzhou.wordpress.com/2011/08/01/beagleboard-angstrom-usb-bluetooth-enable/

http://www.noah.org/wiki/pexpect#Download_and_Installation

http://yetiblog1337.wordpress.com/2013/06/02/raspberry-pi-bluetooth-dongle-does-not-work/

This entry was posted in BeagleBone Black. Bookmark the permalink.

4 Responses to Bluetooth LE on BeagleBone Black with TI SensorTag

  1. Mike Vartanian says:

    Thanks for this useful tutorial… It seems to work much better on the beaglebone than on the pi.

    I ran into a slight issue when trying install pexpect. When initiating the python ./setup.py install command, i receive an ImportError: No module named distutils.core. I am assuming there is some other code I need to download as well?

    Thanks,
    Mike

  2. Mike Vartanian says:

    I now am getting an error with pexpect. It is expecting a resource.py file that is not present. Any suggestions on where to get this file? Or should this not be an issue?

    Thanks,
    Mike

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>