Coder Social home page Coder Social logo

rtduino-libraries / esp-arduino-lua Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sfranzyshen/esp-arduino-lua

0.0 0.0 0.0 267 KB

Lua scripting engine integrated in Arduino IDE as a Library for ESP8266/ESP32

License: GNU General Public License v3.0

C++ 0.31% C 99.69%

esp-arduino-lua's Introduction

Arduino Lua

This Arduino library provides the lua 5.3.6 ( release ) scripting engine for supported devices. This allows dynamic execution of Lua code on the Arduino without having to compile and flash a new firmware.

Supported devices:

  • ESP8266
  • ESP32/ESP32S2/ESP32C3/ESP32S3
  • Arduino Uno R4 Minima/WiFi
  • Raspberry Pi Pico/Pico W

Along with the Lua 5.3.6 Core the following Lua standard libraries are included:

  • base (print(), tostring(), tonumber(), etc.)
  • math
  • table (insert(), sort(), remove(), ...)
  • string (len(), match(), ...)

Sample sketch example: ExecuteScriptFromSerial.ino

After installing the library, some sketch examples are available from the File menu, then Examples and finally under Arduino-Lua. The examples include ExecuteScriptFromSerial which takes a lua script from the serial line and executes it. As an example, the following standard Arduino functions are available in lua scripts as bindings:

  • pinMode()
  • digitalWrite()
  • delay()
  • millis()
  • print() (only builtin binding)
# Enter the lua script and press Control-D when finished:
print("My first test!")
# Executing script:
My first test!


# Enter the lua script and press Control-D when finished-
print("Current uptime: " .. millis())
# Executing script:
Current uptime: 159926.0


# Enter the lua script and press Control-D when finished:
print("Hello world!")
# Executing script:
Hello world!


# Enter the lua script and press Control-D when finished:
pinLED = 2
period = 500
pinMode(pinLED, OUTPUT)
while(true)
do
  print("LED on")
  digitalWrite(pinLED, LOW)
  delay(period)
  print("LED off")
  digitalWrite(pinLED, HIGH)
  delay(period)
end
# Executing script:
LED on
LED off

Resources Used (ExecuteScriptFromSerial.ino)

ESP8266: Sketch uses 327776 bytes (31%) of program storage space. Maximum is 1044464 bytes. Global variables use 31276 bytes (38%) of dynamic memory, leaving 50644 bytes for local variables. Maximum is 81920 bytes.

ESP32: Sketch uses 310749 bytes (23%) of program storage space. Maximum is 1310720 bytes. Global variables use 15388 bytes (4%) of dynamic memory, leaving 312292 bytes for local variables. Maximum is 327680 bytes.

Arduino Uno R4: Sketch uses 133756 bytes (51%) of program storage space. Maximum is 262144 bytes. Global variables use 2836 bytes (8%) of dynamic memory, leaving 29932 bytes for local variables. Maximum is 32768 bytes.

Raspberry Pi Pico: Sketch uses 124736 bytes (5%) of program storage space. Maximum is 2093056 bytes. Global variables use 10352 bytes (3%) of dynamic memory, leaving 251792 bytes for local variables. Maximum is 262144 bytes.

Arduino IDE Library example: HelloWorld.ino

#include <LuaWrapper.h>

LuaWrapper lua;

void setup() {
  Serial.begin(115200);
  String script = String("print('Hello world!')");
  Serial.println(lua.Lua_dostring(&script));
}

void loop() {

}

Resources Used (HelloWorld.ino)

ESP8266: Sketch uses 365276 bytes (34%) of program storage space. Maximum is 1044464 bytes. Global variables use 34712 bytes (42%) of dynamic memory, leaving 47208 bytes for local variables. Maximum is 81920 bytes.

ESP32: Sketch uses 309913 bytes (23%) of program storage space. Maximum is 1310720 bytes. Global variables use 15388 bytes (4%) of dynamic memory, leaving 312292 bytes for local variables. Maximum is 327680 bytes.

The Lua Language:

Lua 5.3 Reference Manual

esp-arduino-lua's People

Contributors

sfranzyshen avatar honestqiao avatar fdu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.