by David Johnson-Davies
Very small Lisp interpreter for Arduino microcomputers

This is a small Lisp interpreter that runs on Atmega-based Arduino microcomputer boards with as little as 2.5KB of RAM. It's mostly intended for measurement and control applications. It's an approximate tiny subset of Common Lisp, with datatypes including 16-bit integers, symbols, and lists. It's written in C (about 22K of compiled code) and includes garbage collection, tail recursion optimization, etc.

(defun clk ()
  (let ((col 2) hr min)
    (go)
    (loop

     ;; Read the time from the RTC
     (with-i2c (str #x68)
       (write-byte 1 str)
       (restart-i2c str 2)
       (setq min (read-byte str))
       (setq hr (read-byte str)))

     ;; Write the time to the display
     (with-i2c (str #x70)
       (write-byte 0 str)
       (dolist (c (list
                   (nth (/ hr 16) seg) 
                   (nth (mod hr 16) seg) 
                   col
                   (nth (/ min 16) seg)
                   (nth (mod min 16) seg)))
         (write-byte c str)
         (write-byte 0 str)))

     ;; Flash the colon
     (setq col (- 2 col))
     (delay 1000))))
Information updated 01/03/17
View Comments