Lua Script Examples (T-Series Only) | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


Lua Script Examples (T-Series Only)

LabJack Lua Scripting

While running a Lua script, the T4, T7, or T7-Pro can operate without computer involvement.  Basically, user-specified operations (feedback loops, logging, PID loops) can be conducted via on-board script, which was not possible in previous generations of LabJack hardware. Below is a screenshot of the Lua Scripting section in our free cross-platform program called Kipling.

Kipling's Lua scripting tab is the best way to develop embedded Lua scripts. It simplifies viewing, testing, and configuring Lua scripts. If you are new to Lua Scripting, see you may wish to see Getting Started.

To view Lua scripts without Kipling, please see our Kipling Git repository. (Our examples are also available in Kipling.)


Key Feature of Lua Scripting: USER_RAM registers

One common application of Lua Scripts is to execute tasks and export status variables to a logging program. These scripts can use USER_RAM registers to pass data from the Lua script to any other program accessing the T-Series device. LabVIEW, C#, Python, or any other supported languages can access the T-Series device and read from or write to these registers. LJLogM can be used for easy logging of data from the various sensors.  Several example scripts like these can be found in the I2C Sensor Examples website section.

One prime example is the Accelerometer & Compass Module (LSM303) example in which a script saves data from the sensor to USER_RAM registers.  The USER_RAM registers can then be logged by LJLogM.

More information:

More can be found in the Lua Scripting section of the T-Series Datasheet.

Maximum Lua Script Size

Reaching the maximum size of a Lua Script using a T7 and T4 is easy to do.  The majority of the scripts that we have written show that the maximum size of a script is right around 100 lines. However, the exact size is hard to determine since it ultimately depends on what variables are being defined, how long is each line of code, etc.  If you start running into some intermittent errors like "not enough memory", it is time to either refactor your code or re-consider how much you are trying to do in a script.  You can try minifying your code using this online Lua Minifier tool.

Maximum Lua Script Speed

See the Lua Script Performance.

Related News Posts

Lua Scripts have been featured in two LabJack news posts: