news

Lua-RTOS for ESP32

Shanghai, China
Apr 27, 2017

A recently-introduced programming environment for ESP32, Lua-RTOS, has been created in Citilab by WhitecatBoard, in Barcelona.

Lua-RTOS is a real-time operating system based on the Lua language, which has been designed to run on embedded systems with minimal requirements of flash and Random-Access Memory. Lua-RTOS is the core of the Whitecat ecosystem, and is currently available for ESP32, ESP8266, and PIC32MZ platforms. However, it can be easily ported to other 32-bit platforms, as well. 

Lua-RTOS has a three-layer design. At the top layer there is a Lua 5.3.4 interpreter with all relevant modules. In the middle layer there is a Real-Time micro-kernel powered by FreeRTOS. Finally, at the bottom there is a hardware abstraction layer which can communicate directly with the platform hardware. When it comes to porting Lua-RTOS to other platforms, programmers need to write code for the bottom layer only, because the top and middle layers can be the same in all platforms. 

Additionally, boards that are compatible with Lua-RTOS can be programmed in two ways: using the Lua programming language directly, or using a block-based programming language that translates blocks to Lua. Using either Lua or blocks is of no particular importance, because both forms of programming are made from the same programming environment. For example, programmers may decide to make a fast prototype by using blocks initially, then change to Lua, and finally get back to using blocks. 

One of the most important characteristics of Lua-RTOS is that it can run Lua functions in native threads. Unlike Lua coroutines, native threads are scheduled by the operating system and all threads share the same Lua state. Although, historically, Lua has been a single-thread programming language, Lua-RTOS gives Lua the capacity to concurrently execute Lua functions for independent tasks which share the same Lua state. The capacity to execute Lua functions in different threads makes Lua RTOS programs more intelligible, as they are written in a manner that is similar to human thought. Lua-RTOS is available as a component of ESP-IDF, which can be accessed here. The relevant Wiki can be found here

Last, but not least, we should mention at this point that the Whitecat ESP32 N1 board was released only a few days ago. The Whitecat ESP32 N1 integrates the ESP32 microcontroller unit with a LoRa WAN transceiver on a single board. ESP32’s Wi-Fi and Bluetooth functionalities along with the LoRa WAN transceiver make the N1 board an ideal platform for the deployment of IoT use cases in both outdoor and indoor environments.