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

  

  

Scripting Tutorial - Lesson 35: BLE - Build Your Own Weather Station 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 a previous lesson of this sequence, we developed a working script to connect to and read temperature data from the TI SensorTag 2.0.

In this lesson, we extend this to more complete capabilities of the Sensor Tag, and collect data from several sensors at the same time! In the process, we will use our SensorTag to build a working weather station!

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.

  
  

Communicating with the TI SensorTag

Top of Page

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 (in this case, light intensity) some bit manipulation of the data is required. For this we use an open source library.

Not surprisingly, these changes do make the script longer than previously, but the essential structure and process remain the same. Study the changes carefully.

Note particularly the way in which the BLE specific function callbackCharacteristics(service) handles the various sensors: reading them remains very much the standard form, but writing to them can vary. For example, while most use string.char(1) as the required signal to trigger the action, and the Barometer first triggers using string.char(1) and then requires string.char(2) to continue.

Interesting, too, to observe that the sensor tag actually delivers FOUR different temperature readings - the ambient and target temperatures that we have discussed previously, but both humidity and barometric pressure data also carry temperature calculations - and rarely do any of these actually agree! Something to ponder on the accuracy of BLE sensor readings in general, perhaps?

The script developed here is, intentionally, simple in design and execution. Many variations might be made to the layout and design of the page, and it is assumed that a mechanism for dropping these results out as stored variables would be very desirable for classroom use. 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.

  
  

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 into lists to this script... or think of ways to take advantage of those neat simple key buttons?

 

 
 

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 = {'Temperature', 'Humidity', 'Baro Pressure', 'Light'}

--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

-- Temperature
local tempRead = 'F000AA01-0451-4000-B000-000000000000'
local tempStart = 'F000AA02-0451-4000-B000-000000000000'
local dieTemp = nil
local irTemp = nil

-- Humidity
local humidData = 'F000AA21-0451-4000-B000-000000000000'
local humidConf = 'F000AA22-0451-4000-B000-000000000000'
local Humidity = nil
local theHumidityTemp = nil

-- 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

 
 

 
 

  
  

The next script in our BLE series offers a simpler change of pace - see how easy it is to collect data from a heart monitor!

  
  

Back to Top

  

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