After setting up Eclipse M2M toolchain for Raspberry Pi, I wanted to try out a simple lua script to blink LEDs using GPIOs. Here is the schematic and lua script for the same. I used the 3.3V available on RPi for powering the LEDs. 1 kiloohm resistors were used to limit the current passing through the LED. The cathodes of the LED were connected to drain the current into the GPIO pins. I used 4 LEDs connected to 4 different GPIOS (GPIO 22, GPIO 23, GPIO 24, GPIO 25).
package.path = '/opt/mihini/lua/?.lua;/opt/mihini/lua/?/init.lua;' .. package.path package.cpath = '/opt/mihini/lua/?.so;' .. package.cpath local gpio = require"gpio" local clock = os.clock local function sleep(n) -- seconds local t0 = clock() while clock() - t0 <= n do end end local function toggle_pin(n) local stat = gpio.read(n) if stat == 1 then gpio.write(n,0) elseif stat == 0 then gpio.write(n,1) end end |
References:
For more detail: LED Blinky in Lua on Raspberry Pi running Mihini on ArchLinux