Paolo Amoroso's Journal

Cardputer

It's a joy to use the Cardputer uLisp Machine, a nice little microcontroller system that runs uLisp. But after a short experience I had to put aside my Cardputer due to a showstopper issue that made it impractical to program the device.

Since then a good workaround emerged and I learned how to improve the experience with the device.

The showstopper is a buffer overflow when sending Lisp code from Emacs to the Cardputer over a serial USB line. If the receive buffer fills up too fast the device will crash and disconnect. Sending more than a few hundred bytes triggers the issue and makes it impractical to evaluate medium or large code blocks. This acknowledged Arduino issue reported in February of 2022 has not been addressed yet.

Meanwhile, Dennis Draheim devised a workaround. He wrote some Emacs Lisp code to open a serial connection to the Cardputer and send an expressions or region for evaluation. The trick is to split the input into lines and send one line at a time, with a delay in between to keep the Cardputer's serial buffer from overflowing.

Dennis' code works well and makes uLisp usable on the Cardputer. The only downside is the echoed input clutters the Emacs serial buffer. Our attempts at turning off echo failed as we don't know where Emacs handles this.

The workaround enables running more substantial and interesting uLisp programs such as this nice surface of rotation graphics demo:

3D function plot on the display of a Cardputer uLisp Machine device.

The Cardputer has a tiny built-in keyboard that is handy for short interactions. But it's prone to overtyping when entering a character that requires pressing two keys, such as shifted characters or the parentheses.

I originally attempted to press at the same time the Aa shift key and the key with the desired symbol. But this often results in typing more than one character as hitting such tiny targets simultaneously is difficult. I later stumbled upon a way to consistently avoid overtyping: I press and hold Aa, then press the key with the desired character.

#Cardputer #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

For Chrismtas 2024 I bought myself a lovely little Cardputer uLisp Machine, an M5Stack Cardputer that can run uLisp.

The M5Stack Cardputer is a card-sized, microcontroller-based portable system for home automation, hobby, and industrial applications. Although not designed for Lisp the Cardputer can run uLisp, an implementation optimized for microcontrollers. This is my unit:

Cardputer uLisp Machine card-sized microcontroller-based computer.

The uLisp system provides a capable Lisp implementation, a rich anvironment, debugging and editing tools, and lots of libraries and examples. It's well maintained and has an active user community.

Motivation

Like many Lispers I always wanted to play with Lisp on the bare metal and the Cardputer uLisp Machine is a simple and inexpensive solution.

uLisp runs on a wide variety of microcontrollers and boards. I picked the ESP32-S3 based Cardputer because it's compact, can run off rechargeable batteries or USB without an external power source, and comes with a graphics display. And at $29.90 it was a no brainer.

Hardware

The Cardputer is a self-contained device with a keyboard, a 240x135 color TFT display, a USB-C port, and a microSD card slot.

Despite the minuscle keyboard, if I hold the Cardputer with both hands I can accurately press any key with my thumbs. However, the keys are very sensitive to pressure and if I hit one with slightly more force than needed I end up repeatedly typing the same character. Entering code and expressions with the built-in keyboard isn't practical for anything longer than a line or two.

The stamp sized display is tiny too but my new eyes help me read the microscopic text on it.

Software

The first thing I did was to install the uLisp firmware to replace the stock system software. The installation procedure is straightforward, took a few minutes, and required only the Arduino IDE which I run on Linux.

There are two main ways of interacting with uLisp. The first is to access the REPL using the Cardputer keyboard and display, the other is to connect from a desktop computer over a USB serial line via the Arduino Serial Monitor or a terminal emulator such as GNU Screen or Minicom. There is also experimental user contributed code for accessing uLisp from Emacs via an inferior Lisp mode or Swank.

A limitation of interacting over USB is that sending code blocks longer than 256 characters overflows the serial buffer, which results in a string of error messages due to the dropped characters.

A workaround is to preceed the code with a comment line starting with a semicolon ; which temporarily turns off echo mode on the device and prevents it from being overwhelmed. Lisp mode on Emacs has no support for the workaround though. So the extra comment line needs to be manually copied from the source buffer and pasted into the inferior REPL along with the code, instead of executing commands such as eval-defun or C-M-x. This introduces friction in the rapid cycles of REPL and editor interactions Lispers are used to.

A showstopper

The limitations of interacting with the Cardputer over serial are just inconveniences that may be fixed by improving existing tools. But a showstopper forces me to set the Cardputer aside until a major Arduino core issue is resolved.

The Cardputer's ESP32-S3 native USB manages the serial port via software and currently has a nasty bug: if the receive buffer fills up too fast the ESP32-S3 will crash and disconnect. I can't do anything practical with the Cardputer without reliably sending medium or large Lisp code blocks to uLisp for evaluation.

The uLisp website does warn about the issue but I incorrectly assumed it affected the Cardputer only when connected to Macs, whereas I use Linux.

Only the Arduino team can fix this issue not caused by uLisp. But since it has been known for a couple of years I’m not holding my breath.

#Cardputer #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org