Raspberry Pi 2 BLE TI Sensor Tag

Install necessary packages:
sudo apt-get install bluez-utils libopenobex1 build-essential libglib2.0-dev libdbus-1-dev

Restart the bluetooth service
sudo service bluetooth restart

Scan for BLE enabled devices connected to the Raspberry Pi:
hciconfig --all

hci0: Type: BR/EDR Bus: USB
BD Address: 00:1A:7D:DA:71:0C ACL MTU: 310:10 SCO MTU: 64:8

Scan for BLE devices:
sudo hcitool lescan

BC:6A:29:AC:53:D1 SensorTag
F4:F9:51:C7:4C:23 (unknown)
BC:6A:29:AC:53:D1 (unknown)
BC:6A:29:AC:53:D1 SensorTag
BC:6A:29:AC:53:D1 (unknown)

It shows two devices, but we are only interrested in the Sensor Tag. The adress is BC:6A:29:AC:53:D1 (this address may be different with each device).
So we know bluetooth is working and the mac address of the sensor tag.

Next step is to download/install the great bluepy library from Ian Harvey:
git clone https://github.com/IanHarvey/bluepy.git
cd bluepy/bluepy

To read now sensor data from the sensortag, use the example script sensortag.py:
usage: sensortag.py [-h] [-n COUNT] [-t T] [-T] [-A] [-H] [-M] [-B] [-G] [-K]

positional arguments:
host MAC of BT device

optional arguments:
-h, --help show this help message and exit
-n COUNT Number of times to loop data
-t T time between polling
-T, --temperature
-A, --accelerometer
-H, --humidity
-M, --magnetometer
-B, --barometer
-G, --gyroscope
-K, --keypress

I.e. to read the temperature five times in an interval of 0.5 seconds we use:
python sensortag.py BC:6A:29:AC:53:D1 -n 5 -t 0.5 -T
then press the button on the side of the sensortag
Connecting to BC:6A:29:AC:53:D1
('Temp: ', (31.71875, 30.4396374686782))
('Temp: ', (31.75, 28.29441505369789))
('Temp: ', (31.71875, 27.21886394070981))
('Temp: ', (31.71875, 27.21886394070981))
('Temp: ', (31.71875, 28.54570004702458))

It is also possible (without any changes to the sensortag.py-script) to use it as a python script:
import time
import sensortag

tag = sensortag.SensorTag('BC:6A:29:AC:53:D1')

for i in range(5):
print tag.IRtemperature.read()
del tag

One remark if you want to import the module from another folder I recommend adding to the __init__.py file the line:
from . import *
Than it is possible to import the package with realtive importing like:
from bluepy.bluepy import sensortag


Ein Gedanke zu “Raspberry Pi 2 BLE TI Sensor Tag

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s