http://www.technoblogy.com/show?2ODQ Logo Technoblogy Arduino and AVR projects [ ] [Search] Recent posts V 2022 * Twinkling Pendant * Morse Code Message Pendant * Controlling RGB LED Strips with a Single Function * 16 LEDs Solution and a New Puzzle > 2021 * Using a Timer on the Arduino Uno or Arduino Zero * AM Morse-Code Transmitter * 16 LEDs Puzzle * Low-Power LCD Clock * Measuring Your Own Supply Voltage * 100MHz Frequency Meter * Pocket Op Amp Lab PCB * Frequency Divider Using CCL * Pocket Op Amp Lab Cookbook * I2C Detective * Pocket Op Amp Lab * Five LEDs Puzzle Solution * Five LEDs Puzzle PCB > 2020 * Compact TFT Graphics Library * Five LEDs Puzzle * Frequency Probe * Combination Lock using CCL * Diffusion Clock * Smooth Big Text * Simple Sprite Routines for the Wio Terminal * Saving Screenshots from a TFT Display * Simple Sprite Routines for the PyGamer/PyBadge * Reading the PyBadge Display * Minimal ATmega4809 on a Breadboard * Big Time * Four Sample Player * Mega Tiny Time Watch [Updated] > 2019 * Eight-Character Alphanumeric Display * Festive Lights Programming Challenge * UPDI Programmer Stick * New ATtiny Low Power * Nano Current Meter * ATtiny Running Lisp * Minimal I2C for the New AVR Microcontrollers * Getting Started with the New ATtiny Chips * Visible Lisp Computer * Simple DataFlash Board * Magic 3D Clock * Tiny TFT Graphics Library * Illuminated Button Matrix * Two-Digit Thermometer * Minimal ATSAMD21 Computer 2 * Minimal ATSAMD21 Computer * Tiny Thermocouple Thermometer * Twelve PWM Outputs from an ATtiny85 * Tiny Function Generator PCB * ATtiny10 Thermometer PCB * ATtiny10 Thermometer * Lisp Badge [Updated] > 2018 * ATtiny85 Weather Station [Updated] * Widget Dashboard * Tiny MIDI Player * Colour Graphics Library * I2C GPS Module PCB * Tiny Terminal 2 * Tiny Function Plotter * I2C GPS Module * Simple LCD Character Display * Alcohol Unit Counter * Tiny Machine-Code Monitor * One Input 20-key Keypad Interface * Programmable Signal Generator * Minimal Tiny I2C Routines * ATtiny85 20MHz Internal Clock * ATtiny10 POV Pendant * IR Remote Wand * IR Remote Control Detective [Updated] * Harmonic Function Generator * Tiny Graphics Library * Secret Maze PCB * Tiny Function Generator Sine Wave * Tiny Function Generator * Secret Maze * Playing Notes on the ATtiny85 * Tiny Colour Watch > 2017 * Continuity Tester * Programming the ATtiny10 [Updated] * Proto Power Supply * Using an ATmega328 without a crystal * Bounce-Free Rotary Encoder * Four-Channel Thermometer * Flexible GPS Parser * Tiny Face Watch * Driving Four RGB LEDs from an ATtiny85 * Big Text for Little Display * ATtiny85 Graphics Display * Tiny Time 2 Watch * 10 or 12-bit DAC from the ATtiny85 * Simple 1-Wire Interface * Audio Pitch Shifter * Tiny Lisp Computer 2 PCB * GameBone Simple Electronic Game > 2016 * Tiny Time Watch * Tiny Lisp Computer 2 * Tiny Lisp Computer * Text Display for the Arduino Uno * Simple PS/2 Keyboard Interface * Making Your Own I2C Peripherals * Using the ATmega1284 with the Arduino IDE * Digital Clock Using Lisp * Making millis() tell the time * A Lightweight Alternative to tone * Adjustable Load * Programming ATtinys with Arduino 1.6.8 [Updated] * Digital Music Box [Updated] * Using the Arduino IDE Without Cores * Flashing Thermometer * Portable Lab Power Supply * ATtiny85 Sound Level Meter > 2015 * ATtiny85 Bargraph Voltmeter * TinyNav Simple GPS Navigator [Updated] * Dot Matrix Clock * Simple Rotary Encoder Interface [Updated] * Driving LED Displays with Fewer I/O Lines * Infrared Controlled Buggy * Powering Projects from a 1.5V Battery * IR Remote Control Switch * Odometer/Speedometer Pendant [Updated] * Push-Button On/Off Switches * Simple ATtiny USI UART 2 * Sony NEX/Alpha Remote Control * IR Remote Control Receiver * Bulls & Cows Game 2 * IR Remote Control Tool (NEC) * IR Remote Control Tool * Bulls & Cows Game * Tiny Terminal * Choosing a Friendly AVR Chip > 2014 * Simple GPS Odometer * Simple Compass Display * Tiny GPS Speedometer [Updated] * Minimal GPS Parser [Updated] * Simple ATtiny USI UART * Timescale Clock * Tiny Synth * Waveform Generation using an ATtiny85 * Audio Sample Player * ATtiny85 Analogue Clock * Radio Time Code Clock * Four PWM Outputs from the ATtiny85 * ATtiny-Based Beginner's Kit * MINIL Machine-Code Monitor * One Input Keypad Interface * Conundrometer Game * Getting Extra Pins on ATtiny * Simple Tones for ATtiny * ATtiny Low Power Topics > Games * Conundrometer Game * Bulls & Cows Game * Bulls & Cows Game 2 * GameBone Simple Electronic Game * Secret Maze * Secret Maze PCB * Five LEDs Puzzle * Five LEDs Puzzle PCB * 16 LEDs Puzzle * 16 LEDs Solution and a New Puzzle > Sound & Music * Audio Sample Player * Simple Tones for ATtiny * Waveform Generation using an ATtiny85 * Tiny Synth * ATtiny85 Sound Level Meter * Digital Music Box [Updated] * A Lightweight Alternative to tone * Audio Pitch Shifter * Playing Notes on the ATtiny85 * Tiny Function Generator * Tiny Function Generator Sine Wave * Harmonic Function Generator * Tiny MIDI Player * Tiny Function Generator PCB * Four Sample Player > Watches & Clocks * Radio Time Code Clock * ATtiny85 Analogue Clock * Timescale Clock * Dot Matrix Clock * Digital Clock Using Lisp * Tiny Time Watch * Tiny Time 2 Watch * Tiny Face Watch * Tiny Colour Watch * Magic 3D Clock * Mega Tiny Time Watch [Updated] * Big Time * Diffusion Clock * Low-Power LCD Clock > GPS * Simple ATtiny USI UART * Simple ATtiny USI UART 2 * Minimal GPS Parser [Updated] * Tiny GPS Speedometer [Updated] * Simple Compass Display * Simple GPS Odometer * Odometer/Speedometer Pendant [Updated] * TinyNav Simple GPS Navigator [Updated] * Flexible GPS Parser * I2C GPS Module * I2C GPS Module PCB > Power Supplies * Portable Lab Power Supply * Adjustable Load * Proto Power Supply > Computers * MINIL Machine-Code Monitor * Tiny Lisp Computer * Tiny Lisp Computer 2 * Tiny Lisp Computer 2 PCB * Tiny Machine-Code Monitor * Lisp Badge [Updated] * Minimal ATSAMD21 Computer * Minimal ATSAMD21 Computer 2 * Visible Lisp Computer * ATtiny Running Lisp * Minimal ATmega4809 on a Breadboard > Graphics * Tiny Terminal * ATtiny85 Graphics Display * Big Text for Little Display * Tiny Graphics Library * Tiny Function Plotter * Tiny Terminal 2 * Colour Graphics Library * Widget Dashboard * Tiny TFT Graphics Library * Reading the PyBadge Display * Simple Sprite Routines for the PyGamer/PyBadge * Simple Sprite Routines for the Wio Terminal * Compact TFT Graphics Library > Thermometers * Flashing Thermometer * Simple 1-Wire Interface * Four-Channel Thermometer * Tiny Graphics Library * ATtiny85 Weather Station [Updated] * ATtiny10 Thermometer * ATtiny10 Thermometer PCB * Tiny Thermocouple Thermometer * Two-Digit Thermometer > Wearables * Odometer/Speedometer Pendant [Updated] * ATtiny10 POV Pendant * ATtiny10 Thermometer PCB * Morse Code Message Pendant * Twinkling Pendant > Tools * IR Remote Control Tool * IR Remote Control Tool (NEC) * IR Remote Control Receiver * Sony NEX/Alpha Remote Control * IR Remote Control Switch * ATtiny85 Bargraph Voltmeter * Driving Four RGB LEDs from an ATtiny85 * Continuity Tester * IR Remote Control Detective [Updated] * IR Remote Wand * Programmable Signal Generator * Alcohol Unit Counter * Illuminated Button Matrix * Simple DataFlash Board * Nano Current Meter * UPDI Programmer Stick * Frequency Probe * Pocket Op Amp Lab * I2C Detective * Pocket Op Amp Lab PCB * 100MHz Frequency Meter > Tutorials * ATtiny Low Power * Getting Extra Pins on ATtiny * One Input Keypad Interface * ATtiny-Based Beginner's Kit * Four PWM Outputs from the ATtiny85 * Choosing a Friendly AVR Chip * Push-Button On/Off Switches * Powering Projects from a 1.5V Battery * Driving LED Displays with Fewer I/O Lines * Simple Rotary Encoder Interface [Updated] * Using the Arduino IDE Without Cores * Programming ATtinys with Arduino 1.6.8 [Updated] * Using the ATmega1284 with the Arduino IDE * Making Your Own I2C Peripherals * Simple 1-Wire Interface * 10 or 12-bit DAC from the ATtiny85 * Bounce-Free Rotary Encoder * Using an ATmega328 without a crystal * Programming the ATtiny10 [Updated] * ATtiny85 20MHz Internal Clock * Minimal Tiny I2C Routines * One Input 20-key Keypad Interface * Simple LCD Character Display * Twelve PWM Outputs from an ATtiny85 * Minimal I2C for the New AVR Microcontrollers * New ATtiny Low Power * Saving Screenshots from a TFT Display * Smooth Big Text * Pocket Op Amp Lab Cookbook * Frequency Divider Using CCL * Measuring Your Own Supply Voltage * Using a Timer on the Arduino Uno or Arduino Zero > PCB-Based Projects * Tiny Time Watch * GameBone Simple Electronic Game * Tiny Time 2 Watch * Tiny Face Watch * Proto Power Supply * Continuity Tester * Tiny Colour Watch * Secret Maze PCB * Tiny Machine-Code Monitor * ATtiny10 POV Pendant * I2C GPS Module PCB * Lisp Badge [Updated] * ATtiny10 Thermometer PCB * Tiny Function Generator PCB * Two-Digit Thermometer * Illuminated Button Matrix * Simple DataFlash Board * UPDI Programmer Stick * Eight-Character Alphanumeric Display * Mega Tiny Time Watch [Updated] * Big Time * Frequency Probe * Five LEDs Puzzle PCB * Pocket Op Amp Lab PCB * Low-Power LCD Clock * 16 LEDs Puzzle * Morse Code Message Pendant * Twinkling Pendant By processor AVR ATtiny > ATtiny10 * Programming the ATtiny10 [Updated] * ATtiny10 POV Pendant * ATtiny10 Thermometer * ATtiny10 Thermometer PCB * Morse Code Message Pendant * Twinkling Pendant > ATtiny2313 * Simple GPS Odometer * Driving LED Displays with Fewer I/O Lines * Dot Matrix Clock > ATtiny84 * Radio Time Code Clock * Timescale Clock * IR Remote Control Tool * IR Remote Control Tool (NEC) * Simple ATtiny USI UART 2 * Odometer/Speedometer Pendant [Updated] * Adjustable Load * Alcohol Unit Counter * Two-Digit Thermometer * Nano Current Meter * Frequency Probe > ATtiny841 * Making Your Own I2C Peripherals * I2C GPS Module * I2C GPS Module PCB > ATtiny85 * ATtiny Low Power * Simple Tones for ATtiny * MINIL Machine-Code Monitor * Four PWM Outputs from the ATtiny85 * ATtiny85 Analogue Clock * Audio Sample Player * Waveform Generation using an ATtiny85 * Tiny Synth * Simple ATtiny USI UART * Tiny GPS Speedometer [Updated] * Simple Compass Display * Tiny Terminal * IR Remote Control Receiver * Sony NEX/Alpha Remote Control * Simple ATtiny USI UART 2 * Push-Button On/Off Switches * IR Remote Control Switch * Infrared Controlled Buggy * Simple Rotary Encoder Interface [Updated] * TinyNav Simple GPS Navigator [Updated] * ATtiny85 Bargraph Voltmeter * ATtiny85 Sound Level Meter * Flashing Thermometer * Digital Music Box [Updated] * Tiny Time Watch * GameBone Simple Electronic Game * Audio Pitch Shifter * Simple 1-Wire Interface * 10 or 12-bit DAC from the ATtiny85 * Tiny Time 2 Watch * ATtiny85 Graphics Display * Big Text for Little Display * Driving Four RGB LEDs from an ATtiny85 * Tiny Face Watch * Flexible GPS Parser * Four-Channel Thermometer * Bounce-Free Rotary Encoder * Continuity Tester * Tiny Colour Watch * Playing Notes on the ATtiny85 * Secret Maze * Tiny Function Generator * Tiny Function Generator Sine Wave * Secret Maze PCB * Tiny Graphics Library * Harmonic Function Generator * IR Remote Control Detective [Updated] * IR Remote Wand * ATtiny85 20MHz Internal Clock * Programmable Signal Generator * Tiny Machine-Code Monitor * Tiny Function Plotter * Tiny Terminal 2 * Colour Graphics Library * Tiny MIDI Player * Widget Dashboard * ATtiny85 Weather Station [Updated] * Tiny Function Generator PCB * Twelve PWM Outputs from an ATtiny85 * Tiny Thermocouple Thermometer * Tiny TFT Graphics Library * Magic 3D Clock * Four Sample Player * Diffusion Clock * Five LEDs Puzzle * Five LEDs Puzzle PCB > ATtiny861 * Portable Lab Power Supply > ATtiny88 * Illuminated Button Matrix AVR ATmega > ATmega328 * Conundrometer Game * Bulls & Cows Game * Bulls & Cows Game 2 * A Lightweight Alternative to tone * Digital Clock Using Lisp * Simple PS/2 Keyboard Interface * Text Display for the Arduino Uno * Tiny Lisp Computer * Using an ATmega328 without a crystal * Proto Power Supply * Simple LCD Character Display * UPDI Programmer Stick * Using a Timer on the Arduino Uno or Arduino Zero > ATmega1284 * Using the ATmega1284 with the Arduino IDE * Tiny Lisp Computer 2 * Tiny Lisp Computer 2 PCB * Lisp Badge [Updated] AVR 0-series and 1-series > ATtiny3216 * ATtiny Running Lisp * Big Time > ATtiny402 * New ATtiny Low Power > ATtiny404 * 16 LEDs Puzzle * 16 LEDs Solution and a New Puzzle > ATtiny414 * Mega Tiny Time Watch [Updated] * 100MHz Frequency Meter * Measuring Your Own Supply Voltage > ATmega4809 * Minimal ATmega4809 on a Breadboard AVR DA/DB-series > AVR128DA28 * Combination Lock using CCL * Frequency Divider Using CCL * Measuring Your Own Supply Voltage > AVR128DA48 * Low-Power LCD Clock > AVR128DB28 * Pocket Op Amp Lab * Pocket Op Amp Lab Cookbook * Pocket Op Amp Lab PCB * Measuring Your Own Supply Voltage ARM > ATSAMD21 * Minimal ATSAMD21 Computer * Minimal ATSAMD21 Computer 2 * Visible Lisp Computer * Using a Timer on the Arduino Uno or Arduino Zero About me * About me * Follow @technoblogy Feeds RSS feed Visible Lisp Computer 14th August 2019 The Visible Lisp Computer is a Lisp interpreter that displays the contents of the Lisp workspace on an OLED display, so you can see program execution and garbage collection in real time: VisibleLispComputer3.jpg Visible Lisp Computer displays the contents of the Lisp workspace on an OLED display as it runs. It's a special version of my uLisp interpreter for ARM boards ^[1], designed to run on an Adafruit ItsyBitsy M0, or an ATSAMD21E on a prototyping board, interfaced to an I2C OLED display. For example, when you evaluate a recursive function, such as the Fibonacci function, you can see the memory being allocated to perform the calculation, and garbage collections clearing unused memory. Apart from being fun, it's educational, giving an insight into how a language with garbage collection works. Introduction The Visible Lisp Computer runs on an Adafruit ItsyBitsy M0, which is an ideal ATSAMD21 board for running uLisp. It's available from Adafruit ^[2], or Pimoroni in the UK ^[3]. The Lisp workspace is displayed on a 64x48 OLED display. This is an ideal fit, as uLisp running on an ATSAMD21 gives you a workspace of 3072 free Lisp objects (each of 8 bytes), and the 64x48 display provides 3072 pixels. I chose a low-cost monochrome I2C display, available from AliExpress ^[4]. The program would also work on larger SSD1306-based OLED displays, such as the widely available 128x64 ones. Free Lisp objects are displayed in black, and when an object is in use it is displayed in white. Periodically you see the garbage collection reclaiming used objects that can no longer be accessed. The circuit Here's how to connect up the display to the Adafruit ItsyBitsy M0: VisibleLispComputer2.gif Circuit of the Visible Lisp Computer based on an Adafruit ItsyBitsy M0. You need pullup resistors of about 4.7kO from SDA and SCL to VCC. Instead of using an Adafruit ItsyBitsy M0 you can build an equivalent Visible Lisp Computer using an ATSAMD21E on a prototyping board by following my earlier project Minimal ATSAMD21 Computer: VisibleLispComputerProto.jpg Version of the Visible Lisp Computer built on a prototyping board. The I2C OLED display connects to GND, VCC, SDA (pin 21), and SCL (pin 22). Again, you need 4.7kO pullup resistors from SDA and SCL to VCC. Example Here's an example of the Visible Lisp Computer in action. First we enter a sample Lisp function to evaluate; I'll use the Fibonacci function, as it should be familiar to most programmers: (defun fib (n) (if (< n 3) 1 (+ (fib (- n 1)) (fib (- n 2))))) Initially the display is black. After entering this in the Serial Monitor the display shows: VisibleLispComputer1.jpg The function is stored in the Lisp workspace as a series of Lisp objects, indicated by the row of white pixels starting in the top left corner. Evaluating the function by entering, for example: (fib 10) allocates Lisp objects as the function is executed, indicated by a white block extending down from the top of the display: VisibleLispComputer2.jpg This call to the Fibonacci function executed within the workspace available, without triggering a garbage collection. If we now evaluate: (fib 16) the function triggers several garbage collections as it executes to reclaim unused objects, while leaving the intermediate values, which are still in use, visible on the display: VisibleLispComputer3.jpg Turning off the workspace display The workspace display is on by default. Because updating the display causes Lisp programs to run more slowly, I've added a Lisp command to turn the display off; give the command: (display nil) To turn it back on again give the command: (display t) The standard version of uLisp does a garbage collection after you input each command at the Serial Monitor or REPL. When running the workspace display this is disabled, to avoid the lag caused by the garbage collection after every line of input. If you want to tidy up the screen display before running a program you can do a manual garbage collection by giving the command: (gc) The program The workspace display interfaces with uLisp in three places. In each case a flag, DISPLAYFLAG, determines whether the workspace display is active. Lisp objects All objects in ARM uLisp consist of two 4-byte cells, so every object occupies 8 bytes. There are several different types of object, such as symbol, number, or cons, identified by the constant in the left-hand cell: Objects1.gif * A symbol contains '2' in the left cell, and the name of the symbol packed in the right cell, or a pointer to the symbol in a symbol table. * A number contains '4' in the left cell, and the 32-bit signed integer value in the right cell. * Finally, a cons contains an address pointer in each cell pointing to other objects. Address pointers are always larger than the largest constant used to identify other types of object. Initialising the workspace When the workspace is first initialised, by calling initworkspace(), all the objects are added to a list of free objects: Objects2.gif The corresponding pixels on the workspace display are plotted in black with a call to PlotObject(): void initworkspace () { Freelist = NULL; for (int i=WORKSPACESIZE-1; i>=0; i--) { object *obj = &Workspace[i]; if (tstflag(DISPLAYFLAG)) PlotObject(i, 0); car(obj) = NULL; cdr(obj) = Freelist; Freelist = obj; Freespace++; } } Allocating an object A Lisp object in the workspace is allocated by a call to myalloc(). It's taken off the freelist and returned by the call. For example, creating the list: (fib 6) will take four objects from the freelist: Objects4.gif The corresponding pixels in the workspace display are plotted in white: object *myalloc () { if (Freespace == 0) error2(0, PSTR("no room")); object *temp = Freelist; Freelist = cdr(Freelist); Freespace--; if (tstflag(DISPLAYFLAG)) PlotObject(((int)temp - (int)Workspace)>>3, 1); return temp; } The address of the object is calculated by subtracting the address of the start of the workspace from the address of the new object, and dividing by eight because each Lisp object is 8 bytes. Freeing an object Finally, a Lisp object is freed by a call to myfree(). It is put on the front of the freelist, and the corresponding pixel in the workspace display is plotted in black: inline void myfree (object *obj) { car(obj) = NULL; cdr(obj) = Freelist; Freelist = obj; if (tstflag(DISPLAYFLAG)) PlotObject(((int)obj - (int)Workspace)>>3, 0); Freespace++; } Objects are freed automatically during garbage collection; the programmer doesn't have to worry about freeing objects. Graphics display routines This display maps each byte in the display memory to a vertical column of eight pixels. Unfortunately the SSD1306 display driver chip doesn't support reading back of the contents of the display memory, so to provide the ability to change a single pixel, without affecting the others in the same column, a copy of the display memory is maintained in RAM; fortunately it's only 384 bytes (64x48/8). The routines used to implement the workspace display are InitDisplay (), to initialise the OLED display, ClearDisplay() to clear the display, and PlotObject(), which plots a pixel corresponding to a Lisp object in the workspace. Uploading the program Whether you're using an Adafruit ItsyBitsy M0, or an ATSAMD21E on a breadboard as described in my article Minimal ATSAMD21 Computer, upload the Visible Lisp Computer as follows: * If you haven't already got it, install the Adafruit SAMD Boards in the Boards Manager. * Select the Adafruit ItsyBitsy M0 board. * Upload the Visible Lisp Computer file to the board. You should then be able to run uLisp, and enter commands at the Serial Monitor as described in Using uLisp. This is based on the current version of uLisp, Version 2.8a, but for simplicity it only supports the Adafruit ItsyBitsy M0 Boards Manager option. Here's the whole Visible Lisp Computer program: Visible Lisp Computer program. Or get it from GitHub here: Visible Lisp Computer. Further suggestions The current project simply distinguishes between an allocated Lisp object (white) and a free object (black). Using a colour display you could use different colours to identify the different types of object: nil, symbol, integer, stream, character, float, string, or cons. --------------------------------------------------------------------- 1. ^ Lisp for microcontrollers on uLisp. 2. ^ Adafruit ItsyBitsy M0 Express on Adafruit. 3. ^ Adafruit ItsyBitsy M0 Express on Pimoroni. 4. ^ White 0.66 inch OLED Display Module 64x48 on AliExpress. --------------------------------------------------------------------- Next: Getting Started with the New ATtiny Chips Previous: Simple DataFlash Board --------------------------------------------------------------------- Please enable JavaScript to view the comments powered by Disqus. blog comments powered by Disqus Copyright (c) 2014-2020