Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 36

  

  

Scripting Tutorial - Lesson 36: BLE - Exploring Movement and Position with the TI Sensor Tag

  

Lesson 30: Welcome to Bluetooth (BLE)

Supplement: Working with Scripts on the iPad

Lesson 31: BLE - Create your own TI-Nspire Remote

Lesson 32: BLE - Measuring Temperature with the Vernier Go Wireless Temp (UPDATED to include Vernier GoLink support)

Lesson 33: BLE - Measuring Heart Rate

Lesson 34: BLE - Measuring Temperature with the TI Sensor Tag

Lesson 35: BLE - Build Your Own Weather Station with the TI Sensor Tag

Lesson 36: BLE - Exploring Movement and Position with the TI Sensor Tag

Lesson 37: Lua, LaunchPads and BLE: Making Music via BLE

Lesson 38: Lua, LaunchPads and BLE: Real world data at your fingertips: Light, Ultrasonic Motion and more...

Lesson 39: Lua, LaunchPads and BLE: Build your own BLE Robot for under $USD40

  

Download supporting files for this tutorial

Download this page in PDF format

Texas Instruments TI-Nspire Scripting Support Page

       
  

In an earlier lesson of this sequence, we developed a working script to use the TI SensorTag 2.0 as a functional weather station.

In this lesson, we extend this to complete the capabilities of the Sensor Tag, and collect data from the movement sensors!

Note: The script on this page is designed for the TI SensorTag 2.0 (Or CC2650 SensorTag). It will not give accurate readings for the original (CC2451) SensorTag. For a general script that works for BOTH tag types, refer to the zipped support files: BLE_Sample_ST.tns.

  
  

Movement, Position and the TI SensorTag

Top of Page

As before, adapting our previous script to take fuller advantage of the TI Sensor Tag is reasonably straightforward:

  1. Add the required UUID values and additional variable names to the initial part of the script (and amend the resetall function).
  2. Extend the paint function to take account of the new values.
  3. Add the required features to the BLE Specific Functions.
  4. In order to access some of the new functionality of the SensorTag 2.0 (movement sensors and light intensity) some bit manipulation of the data is required. For this we use an open source library.

Included among the more obvious "movement" sensors (acclerometer, magnetometer and gyroscope) are the other two "dynamic" sensors (barometer and light intensity), which may also be used to give relatively good information concerning movement and, more interestingly, position!

In fact, with a little systematic measurement and calibration, barometric variations may be used to deliver measure of altitude (or vertical displacement), while light intensity can give us horizontal displacement. Such questions are potentially powerful investigations for STEM-active classrooms, drawing on knowledge of mathematics and science, and taking an engineering approach to solving problems using technology.

The script developed here is, intentionally, simple in design and execution. Many variations might be made to the layout and design of the page. These are left to the reader - or feel free to play with the enhanced BLE_Sample_ST.tns or the more complete TI_SensorTag.tns document which accompanies this tutorials.

Note, however, that this script does include capturing of the live data into lists, which may be dynamically displayed using the Data & Statistics App. The method used here does not actually rely upon the TI-Nspire Lua timer function, but rather on the delivery of data from the SensorTag (by default, this should happen around 10 times a second).

  
  

Once again, if you have a SensorTag and appropriate device, you can test this script yourself by copying and pasting from this page. Of course, prepared versions are also available from the download link for this page.

  
  

Your homework? Try adding storage of data for magnetometer and gyroscope? And try developing classroom-ready activities for students to capture calibration data and convert their lists into distance, and even velocity data...

 

 
 

platform.apilevel = '2.5'

screen = platform.window
w = screen:width()
h = screen:height()

pcall(function () require 'bleCentral' end)

require "color"
local bleState = ''
local bleStatus = 'Stand by'
local peripheralName = ''
local myPeripheral = nil
local nameCheckList = {'Tag 2.0', 'CC2650'}
local nameList = {'TI Sensor Tag 2.0', 'CC2650 SensorTag', 'TI SensorTag 20'}
local sensorList = {'Barometric Pressure', 'Light Intensity', 'Accelerometer', 'Magnetometer', 'Gyroscope'}

local timeList = {}
var.store("timeList", timeList)
local timeIndex = 0
local pause = true
local baTemp = nil
local baroList = {}
var.store("baroList", baroList)
local lightList = {}
var.store("lightList", lightList)
local acc_x = {}
var.store("acc_x", acc_x)
local acc_y = {}
var.store("acc_y", acc_y)
local acc_z = {}
var.store("acc_z", acc_z)

--TI Sensor Tag Init Variables

--Simple Keys
local keysRead = 'FFE1'
local keyPress = nil
local Lstart = 0
local Lstop = 0
local Rstart = 0
local Rstop = 0

-- Barometric Pressure
local baData = 'F000AA41-0451-4000-B000-000000000000'
local baConfig = 'F000AA42-0451-4000-B000-000000000000'
local baCalib = 'F000AA43-0451-4000-B000-000000000000'
local baPeriod = 'F000AA44-0451-4000-B000-000000000000'
local Pa = nil
local baTemp = nil

-- Light
local optData = 'F000AA71-0451-4000-B000-000000000000'
local optSwitch = 'F000AA72-0451-4000-B000-000000000000' -- 0: disable, 1: enable
local optPeriod = 'F000AA73-0451-4000-B000-000000000000' -- Period in tens of milliseconds
local Light = nil

-- Movement
local moveData = 'F000AA81-0451-4000-B000-000000000000'
local moveConf = 'F000AA82-0451-4000-B000-000000000000'
local movePeriod = 'F000AA83-0451-4000-B000-000000000000'

 
 

 
 


  

Back to Top

  

Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 34