Wiki2
Ulisp

Run lisp on Arduino using OpenBSD

I have been fascinated by the ulisp project for some time.

It seems attractive to be able to run a high level language on target using a REPL on a small embedded device.

So I thought I would try it out on an old Arduino board using OpenBSD as host.

These notes assumes OpenBSD 6.4 on the host.

Install arduino on OpenBSD

It turned out the running arduino on OpenBSD is really straight forward.

The process is explained in quite detail in Arduino Development using the OpenBSD CLI.

To install the environment just install package arduino.

# pkg_add arduino

See an intro to the package in:

less /usr/local/share/doc/pkg-readmes/arduino
less /usr/local/share/doc/pkg-readmes/avrdude

Deploy ulisp

Next I created a sample project

arduinoproject ulisp-uno
cd ulisp-uno

I first tried to build and deploy the helloworld.ino source from the link above copied into ulisp-uno.ino.

make

After connecting the board with a USB printer cable I could deploy the hex file.

doas make upload

doas (sudo alternative) is needed for USB access. This makes the arduino blink a LED in a nice and soothing pace.

Next I tried to build ulisp.

wget https://raw.githubusercontent.com/technoblogy/ulisp/master/ulisp.ino
mv ulisp.ino ulisp-uno.ino

Here I got some compile errors that needed to be fixed.

  • Some added forward declarations
  • A new include file eeprom.h
  • A commented out yield() call

I also added some libraries to the Makefile.

LIBRARIES=SPI EEPROM

See https://github.com/peterljung/ulisp for details.

So after another make/upload ulisp was running on the Arduino.

To connect to the device i used cu serial terminal emulator.

cu -s 9600 -l /dev/cuaU0

See Using ulisp for some guidance on how to use the on target repl environment. Here is a sample session.

uLisp 2.6
314> (+ 451 42)
493

314> (defun b () (pinmode 13 t) (loop (digitalwrite 13 t) (delay 500) (digitalwrite 13 nil) (delay 500)))
b

279> (b)
Error: Escape!

The second example is the corresponding blinking hello world in lisp! You escape a running command with ~. You escape the cu serial terminal with ~. ENTER.

See ulisp Language Reference for a complete reference of available commands.

When you are satisfied with your program you can save the image (save-image) (i.e. current state) which you can optionally autorun on hardware reset. See Saving and loading images for more info.

Pretty awesome! But now I wonder if this is something to be used for real deployments?

You can certainly have some serious fun with this

References