eLua Preliminary Port
A preliminary port is now available to use eLua on mbed (currently the NXP LPC1768 version).
Check out the eLua website for general information about the project: http://www.eluaproject.net/
Other Supported Features:
- MBED Filesystem (including directory listing using the ls command)
Note: This port is currently a bare metal GCC-based port to the LPC1768, as such it does not use the online compiler, and requires a GCC toolchain to build fresh images.
eLua v0.7 Copyright (C) 2007-2010 www.eluaproject.org eLua# ls /rom bisect.lua 646 bytes hangman.lua 3378 bytes hello.lua 23 bytes info.lua 134 bytes led.lua 1296 bytes pwmled.lua 1007 bytes dualpwm.lua 932 bytes life.lua 2601 bytes MBED.lua 793 bytes Total on /rom: 10810 bytes /semi MBED.HTM 340 bytes TESTREAD.LUA 194 bytes HELLO.LUA 23 bytes ELUA_L~1.BIN 175640 bytes TESTTEST.TXT 33 bytes TESTFILE.TXT 333 bytes Total on /semi: 176563 bytes Lua# cat /rom/info.lua print( "I'm running on platform " .. pd.platform() ) print( "The CPU is a " .. pd.cpu() ) print( "The board name is " .. pd.board() ) eLua# lua /rom/info.lua Press CTRL+Z to exit Lua I'm running on platform LPC17XX The CPU is a LPC1768 The board name is MBED eLua#
Known issues: dualpwm.lua, which alternately dims and brightens LED1 & 2 using PWM indicates that one can press any key to exit, however it appears to be stuck in the program. This program will run until you reset the mbed.
eLua on MBED Particulars
pio.pin.setdir( pio.OUTPUT, mbed.pio.LED1 ) -- set LED1 pin to output mode pio.pin.sethigh( mbed.pio.LED1 ) -- turn on LED1 pio.pin.setlow( mbed.pio.LED1 ) -- turn OFF LED1
PWM Pin Mapping
|mbed Pin||Peripheral ID||Pin Function|
|mbed Pin||peripheral ID||pin function|
-- configure LED1 for function 2, not in open drain mode (3rd param), -- pin mode zero (4th param) mbed.pio.configpin(mbed.pio.LED1, 2, 0, 0) pwm.setup( 1, 50000, 23 ) -- configure peripheral ID 1 to 50 kHz w/ a duty of 23% pwm.start( 1 ) -- start PWM output
The default function for each pin is 0, so if you need to switch a pin back to general purpose I/O mode, you would need to execute a command similar to:
mbed.pio.configpin(mbed.pio.LED1, 0, 0, 0)
One peripheral that does not require pre-configuration of pins is ADC, since the channels don't have multiple locations that can be mapped. eLua's ADC dev 0 -> 5 correspond to pins p15 -> p20 on the mbed and are enbabled using eLua's style of referencing devices, i.e.: adc.sample(2,4) -- collect 4 samples on channel 2.
Using the Filesystem
filename = "/semi/testfile.txt" f = assert(io.open(filename, "a")) f:write("Looks like filesystem support works!\n") f:close() f = assert(io.open(filename, "r")) print(f:read("*all")) f:close()
If you were to put this on the mbed filesystem as testfs.lua, you could repeatedly run it this way, each time appending the text from the f:write line to the file:
eLua# lua /semi/testfs.lua Press CTRL+Z to exit Lua Looks like filesystem support works! eLua# lua /semi/testfs.lua Press CTRL+Z to exit Lua Looks like filesystem support works! Looks like filesystem support works! eLua# lua /semi/testfs.lua Press CTRL+Z to exit Lua Looks like filesystem support works! Looks like filesystem support works! Looks like filesystem support works! eLua# lua /semi/tesfs.lua Press CTRL+Z to exit Lua Looks like filesystem support works! Looks like filesystem support works! Looks like filesystem support works! Looks like filesystem support works!
For more information on Lua's I/O model, check out the following pages:
Please log in to post a comment.