JeremyGrosser / picolua

A minimal example of Lua with Raspberry Pi pico-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minimal Lua on RP2040

Dependencies

sudo apt update
sudo apt install build-essential gcc-arm-none-eabi git cmake python3 tio

git clone https://github.com/JeremyGrosser/picolua
cd picolua

Build

mkdir build
cd build
cmake ..
make

Run

Hold BOOTSEL button, connect USB.

sudo cp picolua.uf2 /dev/disk/by-label/RPI-RP2
tio -b 115200 /dev/ttyACM0

Usage

Ctrl-C  Clear buffer
Ctrl-D  Execute buffer
Ctrl-L  Clear screen

Examples

lua> print("hello lua")
<Ctrl-D>
hello lua
lua> a=2
b=2
print(a*b)
<Ctrl-D>
4

Binding to Pico SDK

A few simple bindings for SDK functions have been added as examples. Here we turn the LED on:

lua> LED=25
set_output(LED, true)
set_pin(LED, true)
<Ctrl-D>

Blinking is an exercise left to the reader.

The bootsel() function will reset the chip for reflashing as if you'd held down the BOOTSEL button.

Notes

The lua-5.4.6 distribution is copied from the release source tarball with the following modifications:

  • Added src/CMakeLists.txt, which lists all of the .c files except lua.c and luac.c
  • Changed LUA_32BITS to 1 in luaconf.h

References

About

A minimal example of Lua with Raspberry Pi pico-sdk

License:Other


Languages

Language:C 67.6%Language:HTML 30.5%Language:Makefile 0.8%Language:Roff 0.5%Language:CMake 0.3%Language:CSS 0.2%Language:C++ 0.0%