Difference between revisions of "TI SensorTag"

From eLinux.org
Jump to: navigation, search
m
(Before You Start)
Line 29: Line 29:
  
 
* Retrieve the original python BLE scripts from [https://github.com/msaunby/ble-sensor-pi/tree/master/sensortag this github repo].
 
* Retrieve the original python BLE scripts from [https://github.com/msaunby/ble-sensor-pi/tree/master/sensortag this github repo].
*Execute the sensortag.py script to determine if it execute properly (i.e. your linux distribution comes with pexpect); if not, retrieve [http://pexpect.sourceforge.net/pexpect.html pexpect] online (I used v3.2)
+
*Execute the sensortag.py script to determine if it executes properly (i.e. your linux distribution comes with pexpect); if not, retrieve [http://pexpect.sourceforge.net/pexpect.html pexpect] online (I used v3.2)
  
 
* Retrive the '''BLE Address''' of your sensortag
 
* Retrive the '''BLE Address''' of your sensortag

Revision as of 15:07, 21 April 2014



Overview

--

BBB interfaceing with Adafruit's BLE Module

The TI BLE SensorTag is a portable low-power module that uses Blueooth Low Energy (BLE, Bluetooth 4.0) and various sensors to communicate data to any BLE reciever.

TI Sensortag Wiki


The python scripts that interface with the BeagleBone Black were gently modified from msaunby's Raspberry Pi Scripts.

System Outline

The Beaglebone Black runs BoneServer.js which creates a webserver on port ____.

The user selects the ballAndCube picture, which launches ballAndCube.html, ballAndCube.js, and the sensortag.py locally on the server (i.e. the BLE dongle is connected to the server not the client).

The sensortag.py python script outputs data, which is handled as an event streamer by node.js, to stream the data to ballAndCube.js which renders object, and interprets the Gyroscope/Accelerometer Data.

Since the python script, which uses gattool, runs in its own process, the data that it receives is streamed without buffering to the client's ballAndCube.js script.

Before You Start

FlexSensorWiring.jpg
  • Retrieve the original python BLE scripts from this github repo.
  • Execute the sensortag.py script to determine if it executes properly (i.e. your linux distribution comes with pexpect); if not, retrieve pexpect online (I used v3.2)
  • Retrive the BLE Address of your sensortag
  $hciconfig hci0 up
  $hciconfig
  hci0: ...
        UP RUNNING
        ...
  $hcitool lescan
  LE Scan ...
  90:59:AF:0B:84:57 (unknown)
  90:59:AF:0B:84:57 SensorTag
  ^^^ Is the BLE address of your sensorTag
  • Modify sensortag.py with your given bluetooth_adr (see main), socket communication code, and 2's complement code.
   import socket
   import os, os.path
   ...
   # 2's complement as per StackOverflow post
   def twos_comp(val, bits):
        """compute the 2's compliment of int value val"""
        if( (val&(1<<(bits-1))) != 0 ):
            val = val - (1<<bits)
        return val
   
   ...
   
   # In accelerometer function
   # User "client.send( )" instead of print, to send data to your node.js server
   client.send( "A " + str(xyz[0]) + " " + str(xyz[1]) + " " + str(xyz[2]) )
   # the "A", serves as a tag to distinguish between each of the sensors
   
   ...
   
   # In gyroscope function
   # join two bytes to form 16 bit number, make unsigned.
   dx = twos_comp(  (  (v[1]<<8) + v[0] ) , 16 ) + 65536 
   dy =  twos_comp(  (  (v[3]<<8) + v[2]  ), 16 ) + 65536
   dz =  twos_comp( (  (v[5]<<8) + v[4]  ), 16 ) + 65536
   client.send( "G " + str( dx )+ " " + str( dy ) + " " + str(dz)  )
   
   ...
   
   # In main():
   global client
   soc_fd = "/tmp/py_soc" 
   # ^^ Unix socket file that python makes, modify as necessary
   client = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM )
   client.connect( soc_fd )
   # ^^ sets up a Unix stream socket @ soc_fd (see socket man pages)
   
   ...
   # comment out any sensor init code for sensors you don't wish to use
   ...
   except (KeyboardInterrupt, SystemExit):
        # cleanup code 
       client.close()
       os.remove( soc_fd )
       raise
   except:
       pass

Reading and Interpreting Analog Input Data

Sample C Code


****************************************************************/
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <unistd.h>