Lua module for Pi
Lua module for Raspberry Pi
This package provides a Lua module to control the GPIO pins on a Raspberry Pi.
The main functionality is provided by the RPi.GPIO Python Module of Ben Croston.
The following functions have been implemented for Lua:
setup cleanup input output setmode gpio_function setwarnings
The PWM-related functions are not included.
Installation
Download the two GPIO module tarballs (links below) and unpack them in the same directory:
RPi.GPIO-0.5.3a RPi.GPIO.Lua ./RPi.GPIO-0.5.3a ./RPi.GPIO-0.5.3a/RPi ./RPi.GPIO-0.5.3a/source ./RPi.GPIO-0.5.3a/test ./RPi.GPIO.Lua
Now install the Lua Development package.
On Raspbian: sudo apt-get install liblua5.1-0-dev
To compile the Lua module, cd to RPi.GPIO.Lua and run make.
A GPIO.so file will be created, which can be used in your Lua scripts.
Example
01 #!/usr/bin/lua 02 03 local GPIO=require "GPIO" 04 05 --BOARD Pin Layout 06 pins={11, 12, 13, 15, 16, 18, 22} 07 08 print ("Version: "..GPIO.VERSION..", Pi Rev: "..GPIO.RPI_REVISION) 09 10 GPIO.setwarnings(0) 11 GPIO.setmode(GPIO.BOARD) 12 13 for k,v in pairs(pins) do 14 GPIO.setup(v, GPIO.OUT) 15 -- or use table for named variables: 16 -- GPIO.setup{channel=v, direction=GPIO.OUT} 17 end 18 19 for k,v in pairs(pins) do 20 GPIO.output(v, 1) 21 end 22 23 os.execute("sleep 1") 24 25 for k,v in pairs(pins) do 26 GPIO.output(v, (k+1)%2) 27 end 28 29 os.execute("sleep 1") 30 31 for k,v in pairs(pins) do 32 GPIO.output(v, k%2) 33 end 34 35 os.execute("sleep 1") 36 37 GPIO.cleanup()
Downloads
RPi.GPIO.Lua module (5 KB)