Home TI-Nspire STEM HQ TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 47

           


Scripting Tutorial - Lesson 47: Lua Scripting and the TI Innovator™ Hub:

7. Create a General Innovator™ Hub and BLE Document



Download supporting file for this tutorial

Texas Instruments TI-Nspire Scripting Support Page

       
  

Scripting for the Innovator Hub: Lesson 8: Create a General Innovator™ Hub and BLE Document

Top of Page

As we begin to develop content for the TI-Nspire platform that makes use of the amazing learning benefits offered by the Innovator™ Hub, it seems likely that there will increasingly be ways in which the same content may be offered across handheld, desktop and tablets. For the last, then the chance to develop learning tools that correspond between Innovator and BLE seems too good to pass up.

We are already seeing documents which lend themselves to this approach. The Science Through Engineering Design activity STEM: One Giant Leaf for Mankind offers a great example of an excellent learning tool that could be used with the Hub OR on iPad with BLE-enabled devices such as the Vernier Go Wireless Link coupled with TI Light probe, or, of course, the CC2650 SensorTag from TI.

The sample document developed in this lesson will work well across both USB and BLE. Connect an Innovator Hub on handheld or desktop software, and it will automatically connect; run it on an iPad and it will readily link to Vernier Go Wireless Link (or Go Wireless Temp), or to a CC2650 SensorTag. Data from any platform is easily collected using our little OneShotTimer "wait" function and dropped into index and dataList lists, ready for viewing and analysis.

Of course, much more is possible - the included document is just a starting point, and is readily extendable. For example, sensors such as accelerometer, barometer and DHT (Digital Humidity and Temperature) deliver their data in lists. There is an included str2list function which makes it easy to break these into their component elements.

Using such a document as a template for further content development ensures that, where appropriate, we are able to take advantage of the full range of excellent TI Tools for STEM.

  

 
    
  1. Obviously, adding BLE functionality involves adding a bunch of new values to the script - the many UUID values for SensorTag, and for the Vernier Go devices are easily added. Most of these are added at the end of the script so as not to confuse things early on. The values which are likely to change when running the script are defined inside a function which can be easily run to reset things (in this case, inside on.resize.)

    Similarly, the menu definition is shifted to the end as it gets much bigger. We define two menus - one for BLE and the other for Hub platforms.

  2.   
      

  3. A key element for running our existing Innovator script on non-Innovator platforms like the iPad is to avoid the errors that will follow when specialised commands appear. To work around this, we simply place a protected call (pcall wrapper around any Innovator-specific commands.

    )
  4.   
      

  5. All the previous user set-up functions are bundled together here.

  6.   
      
  7. No changes from that previously defined.

  8.   
      

  9. This block of code will serve to connect and run Vernier Go Wireless Link and Temp devices, and TI CC2650 SensorTag.

    Obviously, other BLE devices may be readily added as desired.

    This includes the TI-Nspire iPad Apps using BLE (BlueTooth Low Energy) and the TI MSP432 LaunchPad.

    Use the free Energia software to flash the attached sketch to the LaunchPad via USB, then follow the guides outlined in LaunchPad lessons LP5 and LP6.

    Best results will be obtained using the general LuaHubBLE document found here, which includes a musical keyboard, or you may prefer the general Lua Hub/BLE Control Panel document.

  
     

-- TI Innovator/BLE Init Values

platform.apilevel = '2.7'
local screen = platform.window
local date = "021517"

local hh = platform:isDeviceModeRendering()
local ipad = platform:isTabletModeRendering()

require 'color'
pcall(function() require 'asi' end)

pcall(function () require 'bleCentral' end)

local isBLEavailable = false
local isBLEconnected = false
local isASIavailable = false

local hubStrOn, hubStrOff, msgStr, rxValue, timeStr, delay, repeats, drive
local tempo, key, I
local list1, list2 = {}, {}
local index, dataList = {}, {}
var.store("index", index)
var.store("dataList", dataList)
local inBox = D2Editor.newRichText()
local help = "Connect your device, and use the samples menu to enter different commands. Press 'tabKey' or 'SUBMIT' to try these out: edit them and try your own."

local stChar = nil

function BLEvars()

bleState = ''
connectStatus = ''
peripheralName = ''
peripheralList = {}
alert = 0
bleName = nil
Lstart = 0
Lstop = 0
Rstart = 0
Rstop = 0

sensorVoltage = nil
periodChar = nil
DDSRecord = 1
writeFlag = false
readFlag = false
returnPeriod = nil
sensorPeriod = 100

setPeriodCharacteristic = nil
DDSseekRecCharacteristic = nil
DDSdataCharacteristic = nil
sensorIDCharacteristic = nil

sensorID = nil
sensorLongName = ''
sensorShortName = ''
sensorEqType = nil
sensorPage =nil
sensorA = nil
sensorB = nil
sensorC =nil
sensorUnits = ''
sensorValue = nil

end

BLEvars()

function addMsg(input)

msgStr = input
print(msgStr)
screen:invalidate()

end

function on.construction()

pcall(function() ble.addStateListener(listenerCallback) end)
pcall(function()
-- To run on all platforms, we need to place a protective wrapper around all our TI Innovator commands

TI_Innovator.init(TI_InnovatorStateCallback)
TI_Innovator.setReadListener(TI_InnovatorReadCallback)
TI_Innovator.connect()

end)

refreshMenu() --The menu is becoming a little unwieldy and so has been shifted to the end of the script.

screen:invalidate()
end

 
 

 
 

Back to Top

  

Home TI-Nspire STEM HQ TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 47