How to add and test a LUA script to Open TX Companion

How tos

LUA scripts can make the Taranis radio even more powerful. Here is a little how to with LUA scripts and testing of those scripts. The scripts used in the demo are listed below.

How to add a LUA script to Open TX Companion

OpenTX Companion Testing Telemetry Scripts 

This is the Temp LUA script.

tempscreenlua

temp.lua

— Temp Screen
— Version 0.5 Brad Kelley
— setup for Trex500
local escTemp = 0
local battTemp = 0
local function background()
escTemp = getValue(“Tmp1”)
battTemp = getValue(“Tmp2”)

end
local function run(event)
background()
print(event)

lcd.clear()

lcd.drawText(1,0,’Trex500 Temps’,INVERS)

lcd.drawText(1,15,’Batt Temp:’,0)
lcd.drawText(1,30,battTemp,DBLSIZE)

lcd.drawText(90,15,’ESC Temp:’,0)
lcd.drawText(90,30,escTemp,DBLSIZE)

end
return { background=background, run=run }

 

 

Here is the  Head speed Calc LUA script.

headspeed

head.lua

— Headspeed Calc
— Version 1.0 Brad Kelley
— setup for Trex500
local maingear = 162
local piniongear = 14
local rpm = 18000
local gearratio = 0
local headspeed = 0

local function init()
gearratio = math.floor((maingear / piniongear) * 100 ) / 100
rpm = getValue(“RPM”)
end
local function background()
rpm = getValue(“RPM”)

headspeed = math.floor((rpm / gearratio) * 100 ) / 100

end
local function run(event)
background()
print(event)

lcd.drawText(1,0,’Trex500 Headspeed’,INVERS)

lcd.drawText(1,15,’Main Gear:’,SMLSIZE)
lcd.drawText(60,15,maingear,SMLSIZE)

lcd.drawText(1,22,’Pinion Gear:’,SMLSIZE)
lcd.drawText(60,22,piniongear,SMLSIZE)

lcd.drawText(1,29,’Gear Ratio:’,SMLSIZE)
lcd.drawText(60,29,gearratio,SMLSIZE)

lcd.drawText(1,43,’RPM:’,SMLSIZE)
lcd.drawText(40,43,rpm,SMLSIZE)

lcd.drawText(90,15,’Head Speed:’,0)
lcd.drawText(90,30,headspeed,DBLSIZE)

end
return { init=init, background=background, run=run }