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

           


Scripting Tutorial - Lesson 34: BLE - Measuring Temperature 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

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


Download supporting files for this tutorial

Download this page in PDF format

Texas Instruments TI-Nspire Scripting Support Page

       
  

In the previous lesson of this sequence, we developed a working script to connect to and read temperature data from a Vernier Go Wireless Temperature probe.

In this lesson, we extend this to the TI Sensor Tag 2.0 using almost the same script with just a few variations.

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 2.0

Top of Page

The TI Sensor Tag offers a wonderful array of sensors for collecting real world data: temperature, barometric pressure, light intensity, humidity, acceleration, magnetic field and gyroscope. We will develop scripts for all of these.

We begin with temperature, and uniquely, this device collects TWO different types of temperature data: ambient (or die) temperature (like the Vernier probe) but also target or infra-red (IR) temperature. The SensorTag has a small window - point this at the nearest object and it will read the temperature of that object! Very handy for boiling water and other situations where the device might suffer from too close an encounter!

Because the SensorTag has so many different functions, there is a little more interaction required than for the simple case of the Vernier probe. For example, the TI Sensor Tag uses some 15 UUID values. Each of the six sensors uses at least two: one for reading, and frequently, one for writing to the device (for starting, or setting the sampling period, for example.) The two temperature UUIDs are:

  • tempRead = 'F000AA01-0451-4000-B000-000000000000'

  • tempStart = 'F000AA02-0451-4000-B000-000000000000'

Only three changes are required to the Vernier script developed in the last lesson to adapt for the Sensor Tag.

  • Click the 'init' button to see minor changes to the previous Vernier script to adapt for the SensorTag.
  • The two temperature variables for the Sensor Tag are named dieTemp and irTemp (but could have easily been something common, like Temp1 and Temp2). Instead of the second reading giving Fahrenheit, it provides the Target Temperature in this case.
  • All other functions are common to both devices, so all that remains is to make some adjustments to the last two functions.
  •   
      

    Specific BLE Functions for the TI Sensor Tag 2.0

    Study the two specific functions for the SensorTag and compare with those for the Vernier temp probe.

    The first difference you should note is that the callbackCharacteristics(service) function checks both tempRead and tempStart. This script not only reads from the BLE device, but writes to it. Writing string.char(1) serves to notify the device to begin collecting data.

    The callbackCharacteristic(characteristic) function takes the read data, and unpacks it - note that this data consists of both signed and unsigned elements, and these must be unpacked separately as shown. Like the Vernier data, the SensorTag ambient temperature data is easy to compute - after unpacking, the dieTemp simply takes the first two bits and divides these by 128. The irTemp does the same with the last two bits.

     

     
     

    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 characteristicsFound = 0

    --TI Sensor Tag Init Variables

    local tempRead = 'F000AA01-0451-4000-B000-000000000000'
    local tempStart = 'F000AA02-0451-4000-B000-000000000000'
    local dieTemp = nil
    local irTemp = nil
    local units = '°C'
    local nameCheckList = {'Tag 2.0', 'CC2650'}
    local nameList = {'TI Sensor Tag 2.0', 'CC2650 SensorTag', 'TI SensorTag 20'}

     
     

     
     

      
      

    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, including a script which will check for and read from both Sensor Tag and Vernier probe. Your home work is to study how this script is just an extension of the two individual scripts we have developed here.

    In our next lesson, we will generalise this script to collect data from all of the Sensor Tag sensors.

      
      

    Back to Top

      

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