Skip to content

sivieri/lua-firmata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Firmata for Lua

This is a porting of the Processing library for Firmata (which, by the way, needs modifications to work with Processing 2.0, but this is another story). The arduino.lua file is the library itself, with code for reading and writing digital and analog values to and from an Arduino running a compatible version of Firmata; the code has been tested with Arduino Uno and Firmata 2.3 (distributed with Arduino IDE 1.0.5). The example simply blinks the test led (pin 13) every two seconds, and reads values from a sensor connected to the first analog pin (A0) when it changes the led status.

A coroutine scheduler is used to wait for data coming from the serial port and sending commands at the same time (the dispatcher can be found here); a numeric library is needed to perform bitwise operations (the source code can be found here). I added the code for these libraries here as it is easier to directly test it, but you can substitute them if you want. There are probably faster and better bitwise libraries, written in C, but I didn't want to have to cross-compile C code when testing on different hardware (e.g., OpenWRT). The same stands for the scheduler: you can write your own and use it instead of the one I include here.

Two important observations:

  • the example slightly changes when run on Carambola, which is a device running OpenWRT, due to differences in how the gettimeofday system call is handled
  • please, forgive any programming error: this is my first program written in Lua, so there may be mistakes well hidden somewhere...

About

Porting of Firmata in Lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages