Show HN: MicroLua – Lua for the RP2040 Microcontroller (github.com)
MicroLua allows programming the RP2040 microcontroller in Lua. It packages the latest Lua interpreter with bindings for the Pico SDK and a cooperative threading library.
MicroLua is licensed under the MIT license.
I wanted to learn about Lua and about the RP2040 microcontroller. This is the result :)
34 comments
[ 2.4 ms ] story [ 87.0 ms ] thread‡ https://fennel-lang.org/
https://github.com/MicroLua/MicroLua/commit/b9dfa2407afe932b...
When I was 12-13 and had an R4 for my DS, I managed to install MicroLua and program some simple apps that showed shapes when the screen was touched in specific areas.
Looking at the page, I see it even has full Wi-Fi and Local Wireless support !
I think it's inactive now, though.
https://eluaproject.net/
The few convenient things that expect tables to be indexed using integers starting at 1 are the # operator to get the number of elements, and the ipairs function, used in the common idiom “for index, value in ipairs(t) do . . . end”.
Probably the number one reason not to start arrays at 0 in an educational language is that having the last element of an array of size 10 have an index of 9 causes quite a bit of confusion.
Other than that, nodeMCU is much more advanced :)
Apache Arrow's C GLib implementation works with Lua. From https://news.ycombinator.com/item?id=38103326 :
> Apache Arrow already supports C, C++, Python, Rust, Go and has C GLib support Lua: https://github.com/apache/arrow/tree/main/c_glib/example/lua
LearnXinYminutes Lua: https://learnxinyminutes.com/docs/lua/
OpenWRT is a Make-based Linux distro for embedded devices with limited RAM and flash ROM, x86, and docker. OpenWRT is built on `uci` (and procd and ubusd instead of systemd and dbus). UCI is an /etc/config/* dotted.key=value configuration system which procd sys-v /etc/init.d/* scripts read values in from when regenerating their configuration when $1 is e.g. 'start', 'restart', or 'reload' per sys-v. LuCI is the OpenWRT web UI which is written in Lua; which is now implemented mostly as a JSON-RPC API instead of with server-side HTML templates for usability and performance on embedded devices.
Notes on how to write a LuCI app in Lua: https://github.com/x-wrt/luci/commit/73cda4f4a0115bb05bbd3d1...
applications/luci-app-example: https://github.com/openwrt/luci/tree/master/applications/luc...
openwrt/luci//docs: https://github.com/openwrt/luci/tree/master/docs
https://openwrt.org/supported_devices
It's probably impossible to build OpenWRT (and opkg packages) for an RP2040W.
https://github.com/raspberrypi/pico-sdk/ links to a PDF about connecting to the interwebs with a pi pico: "Connecting to the Internet with Raspberry Pi Pico W" https://rptl.io/picow-connect
micropython/micropython//ports/rp2/boards/RPI_PICO_W: https://github.com/micropython/micropython/tree/master/ports...
micropython/micropython//lib: https://github.com/micropython/micropython/blob/master/lib
micropython/micropython//examples/network/http_server_simplistic.py: https://github.com/micropython/micropython/blob/master/examp...
micropython/micropython//examples/network/http_server_ssl.py: https://github.com/micropython/micropython/blob/master/examp...
raspberrypi/pico-sdk//lib: btstack, cyw43-driver, lwip, mbedtls, tinyusb https://github.com/raspberrypi/pico-sdk/tree/master/lib
raspberrypi/pico-examples//pico_w/wifi/access_point/picow_access_point.c: https://github.com/raspberrypi/pico-examples/blob/master/pic...
There's an iperf opkg pkg, or is it just netperf (which works with the flent CLI and GUI)?
raspberrypi/pico-examples//pico_w/wifi/iperf/picow_iperf.c: https://github.com/raspberrypi/pico-examples/blob/master/pic...
raspberrypi/pico-examples//pico_w/wifi/freertos/iperf/picow_iperf.c: https://github.com/raspberrypi/pico-examples/blob/master/pic...
FreeRTOS > Process management: https://en.wikipedia.org/wiki/FreeRTOS#Process_managememt
elf2uf2: https://github.com/raspberrypi/pico-sdk/tree/master/tools/el...
adafruit/circuitpython//tests/micropython: https://github.com/adafruit/circuitpython/tree/main/tests/mi...
adafruit/circuitpython//tools: [deleted] ↗ (comment deleted) bmitc ↗ This is very cool. Thanks for sharing this. rblank ↗ I can't really give advice for creating a new language, or even for creating a new implementation of an existing one. MicroLua uses the existing Lua implementation from lua.org, and just packages it to make it useful on a specific platform. bxparks ↗ Does Lua have primitive arrays now? When I looked at it some years ago, it seemed to support only hash maps, and arrays were emulated using hash maps, which I found to be completely bizarre. There were discussions online where Lua folks were saying, no, you don't really need arrays. And I'm thinking to myself, hell yeah, I really needs arrays on resource-constrained microcontroller systems without garage collection. vore ↗ If a table is contiguously indexed by integers from 1, the storage is optimized into an array. ckolkey ↗ Yeah, tables serve as both lists and maps. You can even have a table with _both_. debugnik ↗ That discussion must have been really long ago, otherwise you missed the point. Since Lua 5.0 (2003) tables are implemented as a pair of an array and a hashmap, and the array part can even handle small nil gaps. So tables used as arrays are implemented as arrays as well. [deleted] ↗ (comment deleted) skibz ↗ You've got an eye for detail. Impressive work! rblank ↗ Thanks for the kind words :) rcarmo ↗ Oh good! Any plans to include fennel? It would be awesome to have another embedded LISP-like language. ktpsns ↗ Another Lua implementation for MCUs posted recently:
I have wanted to do something similar for either an existing language or a subset of such or for a minimal language I create. Do you have any suggestions on how to get started on that in terms of high-level steps?
For that, it helps if the existing implementation is already cross-platform and has few dependencies. Lua is great in this respect, as it only depends on a libc. The first step is to get it to compile for the target platform and have it execute a hard-coded "hello world" script. After that, it's only a matter of adding more libraries, one at a time.
Roughly how long did it take you to get to this point?
I've been working on this in my spare time since March, so roughly 8 months.
https://news.ycombinator.com/item?id=38067457