Now Reading
Technoblogy – Lisp Badge LE

Technoblogy – Lisp Badge LE

2023-09-27 17:27:11

Lisp Badge LE

twenty seventh September 2023

It is a self-contained low-power laptop with its personal show and keyboard you can program in uLisp, a model of the high-level language Lisp for microcontrollers:

LispBadgePulse.jpg

The Lisp Badge LE, a low-power laptop programmed in Lisp
with a self-contained keyboard and show.

It is primarily based on an AVR128DB48 which offers 128K bytes of flash reminiscence, and 16K bytes of RAM. There’s an built-in 45-key keyboard optimised for Lisp, utilizing reverse-mounted buttons giving room for giant key legends on the PCB.

It has a low-power monochrome show, readable in daylight with no backlight, so it is preferrred for programming within the backyard or on the seashore! This offers 10 traces of 41 characters, or graphics with a decision of 250×122 pixels, supported by a number of graphics instructions.

You should use it to run packages that interface to parts akin to LEDs and push-buttons through the I/O pins, learn the analogue inputs, and function exterior units through the I2C and SPI interfaces.

Introduction

A number of years in the past I designed the Lisp Badge, a self-contained laptop with its personal show and keyboard, primarily based on an ATmega1284, that you may program in Lisp. Since then I have been fascinated with how I may enhance it, and made a listing of options I might like so as to add.

On the one hand I wished it to have a greater keyboard, and be low energy, powered from a button cell, with an eInk show that you may see in daylight. However I wished it to have a color TFT graphics show, and use a quick 32-bit ARM processor, with help for floating-point arithmetic.

I quickly realised that these necessities are incompatible in a single design, and so set about designing two completely different Lisp Badges to satisfy the 2 units of necessities. This Lisp Badge LE (low power) is the primary of these designs, and has the next new options:

Processor and reminiscence

It’s primarily based on an AVR128DB48 (or AVR128DA48) operating at 24MHz, and offers 2800 Lisp objects, about the identical as the unique Lisp Badge. It can save you all the workspace to flash.

Present consumption

The Lisp Badge LE attracts solely 6mA from its CR2032 button cell, and so ought to have a lifetime of about 40 hours. There’s a bodily on/off swap too for lengthy durations of inactivity.

Lisp language

The Lisp Badge LE runs the AVR model of uLisp which offers 16-bit integer arithmetic, arbitrary size symbols and strings, lists, multi-dimensional arrays, Arduino interface capabilities, debugging options, and built-in documentation.

Show

The show is a low-power monochrome graphics show [1] which I explored in an earlier article; see Monochrome Low-Power Display Library. It has a decision of 250×122 pixels, and a textual content decision of 10 traces of 41 characters per line. It helps studying again from the show, which makes it potential to help a full vary of graphics capabilities, together with plotting factors, drawing traces, drawing define and crammed rectangles circles or triangles, and plotting characters and textual content at regular measurement or enlarged by any integer scale issue.

Keyboard

The keyboard takes benefit of push buttons that mount on the reverse of the board, with the button caps protruding by holes within the PCB. This makes it a lot simpler to make use of than on the unique Lisp Badge as a result of it is simpler to press the keys, and there is house for bigger key legends. The push buttons can be found from Adafruit [2]. or The Pi Hut within the UK [3].

It makes use of the identical 45-key format as the unique Lisp badge, with higher and lower-case characters, digits, and the symbols required by uLisp. Nonetheless, it now offers an addition META modifier key along with SHIFT, permitting you to enter characters that do not have a devoted key on the keyboard.

Peripherals

There’s a big piezo speaker that helps enjoying notes, and a reverse-mounting LED that shines by a gap on the entrance of the board.

Here is the complete specification:

Lisp Badge – Specification

Dimension: 107mm x 61mm (4.2″ x 2.4″).

Show: 41 characters x 10 traces, or 250 x 122 pixels.

Keyboard: Built-in 45-key keyboard offering higher and lower-case characters, digits, and the symbols required by uLisp.

The META key pressed together with one other key provides entry to the next characters not accessible from the primary keyboard:

META + A C D E P Q T U V < >
Character & : $ ! % ? @ ^ | { }

Reminiscence accessible: 2800 Lisp cells (11200 bytes).

Flash: 16384 bytes of flash are reserved to be used to save lots of the Lisp workspace utilizing save-image.

Processor: AVR128DB48

Clock pace: 24 MHz.

Present consumption: Approx. 6 mA. A CR2032 cell has a typical capability of 225 mAh, so this could give a lifetime of about 40 hours.

Varieties supported: record, image, integer, character, string, stream, and array.

An integer is a sequence of digits, optionally prefixed with “+” or “-“. Integers may be between -32768 and 32767. You may enter numbers in hexadecimal, octal, or binary with the notations #x2A, #o52, or #b101010, all of which characterize 42.

Person-defined image names can have arbitrary names. Any sequence that is not an integer can be utilized as an emblem; so, for instance, 12a is a legitimate image.

There may be one namespace for capabilities and variables; in different phrases, you can not use the identical identify for a operate and a variable.

Features a mark and sweep rubbish collector. Rubbish assortment takes 5 msec.

Language

uLisp, a subset of Widespread Lisp, with the next 196 Lisp capabilities and particular kinds:

* + – / /= 1+ 1- < <= = > >= ? abs analogread analogreadresolution analogreference analogwrite and append apply apropos apropos-list aref array-dimensions arrayp ash assoc atom bit boundp break caaar caadr caar cadar caddr cadr automobile case cdaar cdadr cdar cddar cdddr cddr cdr char char-code characterp check-key closure cls code-char concatenate cond cons consp dacreference decf defcode defun defvar delay digitalread digitalwrite documentation dolist dotimes draw-char draw-circle draw-line draw-pixel draw-rect draw-triangle edit eq equal error eval evenp fill-circle fill-rect fill-screen fill-triangle first for-millis format funcall gc get-pixel globals glyph-pixel if ignore-errors incf integerp keyboard keywordp lambda size let let* record list-library listp load-image locals logand logbitp logior lognot logxor loop make-array makunbound mapc mapcan mapcar max member millis min minusp mod not notice nothing nth null numberp oddp or pinmode plot plot3d plusp pop pprint pprintall prin1 prin1-to-string princ princ-to-string print progn push quote random learn read-byte read-from-string read-line register require relaxation restart-i2c return reverse room save-image search second set set-cursor setf setq sleep kind streamp string string< string= string> stringp subseq symbolp t terpri third time hint truncate until untrace unwind-protect when with-i2c with-output-to-string with-sd-card with-serial with-spi write-byte write-line write-string zerop

It additionally offers 37 key phrases akin to :enter, :output, and :led-builtin, as a handy method of coming into Arduino constants.

For a full definition see uLisp Language Reference.

Graphics extensions

The Lisp Badge LE features a graphics library to will let you do plotting on the show; for particulars see Graphics extensions. These work utilizing a coordinate system with the origin at high left:

GraphicsDisplayCoords5.gif

The next instance exhibits a plot of the fractal Dragon Curve; for this system see Dragon curve:

LispBadgeLEDragon.jpg

A fractal Dragon Curve drawn in Lisp on the Lisp Badge LE utilizing the graphics extensions.

Assembler

The Lisp Badge LE additionally consists of an AVR assembler which lets you generate and run machine-code capabilities, written in AVR mnemonics, utilizing an assembler written in Lisp. For particulars see AVR assembler overview.

The language consists of a number of extensions particularly for the Lisp Badge, together with plot and plot3d, for plotting graphs and 3d capabilities, and keyboard and check-key for studying the keyboard in actual time. For particulars see Lisp Badge LE extensions.

Interfaces

These interfaces are dropped at headers on the fringe of the Lisp Badge LE board. The numbers in brackets confer with Arduino pin numbers:

  • Eight analogue enter pins utilizing analogread: PD0 to PD7 (22 to 29).
  • VCC, GND, and UPDI.
  • Two analogue outputs utilizing analogwrite: MOSI0 (4) and MISO0 (5).
  • Digital enter and output utilizing pinmode, digitalread, and digitalwrite: TX0 (0), RX0 (1), SCL0 (2), SDA0 (3), MOSI0 (4), MISO0 (5), SCK0 (6), and PD0 to PD7 (22 to 29)
  • I2C interface utilizing with-i2c and restart-i2c: SCL0 (2) and SDA0 (3), plus VCC and GND.
  • SPI interface utilizing with-spi: MOSI0 (4), MISO0 (5), and SCK0 (6), plus VCC and GND.
  • Serial interface (FTDI) utilizing with-serial: TX0 (0) and RX0 (1), plus DTR, VCC, and GND.

Analogue output PB4 (12) is related to a piezo speaker, which might use analogwrite or notice.

The SHIFT (33) and META (11) keys can be utilized as digital inputs, learn with digitalread and referenced as :shift-key and :meta-key.

PA7 (7) is related to an LED on the entrance panel, referenced as :led-builtin. You may flip it on and off with digitalwrite, or fluctuate its brightness with analogwrite.

Getting into packages

You may enter instructions and packages by typing them on the keyboard, and urgent ENTER. A keyboard buffer is offered that buffers a full display of textual content, and you should use the DEL key to delete characters and proper typing errors. The road editor consists of parenthesis matching which mechanically highlights matching brackets in inverse video as you kind in a program. This makes it a lot simpler to enter a program accurately, and is very useful in telling you what number of closing brackets to kind on the finish of defining a operate.

For instance, the next program pulsates the built-in LED slowly on and off:

(defun pulse (&non-compulsory (up t))
  (dotimes (x 256)
    (analogwrite :led-builtin (if up x (- 255 x)))
    (delay 8))
  (pulse (not up)))

It is proven properly formatted right here for readability, however you possibly can kind it in as one steady line, solely urgent ENTER on the finish. To run this system kind:

(pulse)

Connecting to a pc

You may join the Lisp Badge to a pc by plugging a 3.3V FTDI USB-to-serial converter onto the FTDI connector on the highest proper of the Lisp Badge, after which connecting this to the pc utilizing a USB cable. You may then use the Serial Monitor within the Arduino IDE to enter and edit packages as described in Using uLisp.

I used the three.3V FTDI Fundamental Breakout from Sparkfun [4]. When utilizing it with the Lisp Badge it powers the Lisp Badge, and so the battery ought to be left switched off.

The circuit

Here is the primary a part of the circuit:

LispBadgeLE.gif

Circuit of the Lisp Badge, primarily based on an AVR128DB48 microcontroller.

The keyboard arranges the keys in a matrix of 4 rows and 11 columns:

LispBadgeKybd.gif

The circuit of the Lisp Badge keyboard matrix.

► Parts list

Development

I created a PCB in Eagle, and ordered a set of boards from PCBWay. I selected white PCBs to distinction with the black buttons. The board is similar width as the unique Lisp Badge, however barely taller to accomodate the bigger show.

After a little bit of experimentation I selected a board thickness of 1.2mm. With the usual 1.6mm thick PCB materials the reverse-mounted buttons did not protrude far sufficient by the holes, and 0.8mm made the boards too flexible, however 1.2mm was preferrred.

The parts, other than the show, are mounted on the again of the board:

LispBadgeLEBack.jpg

The reverse aspect of the Lisp Badge printed circuit board.

See Also

The push buttons are mounted at a 15° angle, which makes it potential to pack them nearer collectively. I’ve taken benefit of the truth that the terminals on both sides of the push buttons are related collectively to hyperlink the rows and columns of the important thing matrix throughout the board, and simplify the PCB observe format. A consequence of that is that if one push button is omitted, or has a defective connection, all the opposite buttons to its left or beneath it throughout the keyboard might not work. Understanding this could aid you observe down any defective soldering.

The PCB makes use of 0805 resistors and capacitors. The LED is a reverse-mounting 1206 LED [5] to make the entrance of the board flush.

The board will accommodate both a 16 x 16mm SMD piezo speaker [6], or a 11 x 9mm SMD piezo speaker [7].

The battery holder is an SMD 20mm coin cell holder accessible from Sparkfun [8], or from Proto-PIC within the UK [9]. Be aware that on many button cells the detrimental terminal is concave, and does not make good contact with the pad on the PCB. I due to this fact suggest melting some solder on the round PCB contact to offer additional thickness earlier than mounting the battery holder.

The show is held in place with a double-sided self-adhesive foam pad, after which soldered to the board with the seven header pins. There are additionally 4 mounting holes if you happen to choose to make use of screw mounting. I like to recommend leaving the show uninstalled till you’ve gotten examined the remainder of the board, as a result of it is prone to be delicate to overheating.

I used a Youyue 858D+ scorching air gun at 275°C to solder the small SMD parts and push buttons, after which used a standard soldering iron for the show, battery holder, swap, piezo speaker, and connectors.

The PCB has house for a 5 x 3.2mm 32.768kHz crystal and its capacitors which you may use with the RTC peripheral to offer correct timekeeping. Nonetheless, I did not match it on the prototype as the interior clock is already fairly correct.

This system

The Lisp Badge program is predicated on the code for the AVR model of uLisp Model 4.4 (see Download uLisp), with the addition of routines to deal with the show and keyboard, and the plot extensions.

Show

The show routine is predicated on the routine I developed for the show in my mission Monochrome Low-Power Display Library. The show driver is the ST7302 [10], and it shares some similarities with the ST7735 used for color TFT shows. Here is the show format:

GraphicDisplayLayout3.gif

The show is split into 11 traces, every of which is 12 pixels excessive, and 125 columns, every of which is 2 pixels large. Be aware that as a result of 122 is not an actual a number of of 12, solely a part of the final line really seems on the show.

Not like on the color TFT shows every pixel is not individually addressable; in actual fact, the minimal replace is to jot down three bytes to the show, which defines the state of a block of 2×12 pixels corresponding to at least one column and one row. Luckily the show helps studying again the show reminiscence, so it isn’t needed to take care of a replica of the show in RAM to do issues like line drawing; as an alternative, to set a single pixel we are able to learn the 2×12 block, change one pixel, and write it again.

Studying from the show

The routine ReadBlock() reads a 12×2 pixel block from the show reminiscence specified by the column, from 0 to 124, and the road, from 0 to 10:

uint32_t ReadBlock (uint8_t column, uint8_t line) {
  uint32_t pix = 0;
  PORT_TOGGLE(1<<cs);
  Command2(CASET, 25+line, 25+line);
  Command2(RASET, column, column);
  Command(RAMRD);
  PORT_INPUT(1<<mosi);                     // mosi enter
  for (uint8_t i=0; i<25; i++)  (PORT_IN>>mosi & 1);
    PORT_TOGGLE(1<<sck);
  
  PORT_OUTPUT(1<<mosi);                    // mosi output
  PORT_TOGGLE(1<<cs);
  return pix;
}

When studying from show reminiscence you need to do a dummy learn, which is why the primary loop is executed 25 instances slightly than 24 instances.

The companion routine PlotBlock() writes again a 12×2 pixel block to the show reminiscence:

void PlotBlock (uint32_t block, uint8_t column, uint8_t line) {
  PORT_TOGGLE(1<<cs);
  Command2(CASET, 25+line, 25+line);
  Command2(RASET, column, column);
  Command(RAMWR); Knowledge(block>>16); Knowledge(block>>8); Knowledge(block);
  PORT_TOGGLE(1<<cs);
}

Scrolling

The show does not present {hardware} scrolling within the vertical course, so scrolling is completed in software program by calling ScrollDisplay(), which makes use of the ReadBlock() and PlotBlock() routines:

void ScrollDisplay () {
  uint32_t block, block2;
  for (uint8_t x = 0; x < Columns*3; x++) {
    block = ReadBlock(x, 0);
    for (uint8_t y = 1; y < Strains; y++) {
      block2 = ReadBlock(x, y);
      if (block2 != block) {                   // Optimisation if already the identical
        PlotBlock(block2, x, y-1);
        block = block2;
      }
    }
  }
  ClearLine(LastLine);
}

The routine optimises the scrolling by solely writing blocks when needed if they’ve been modified by the scrolling.

Keyboard

The keyboard makes use of the AVR128DB48’s Timer/Counter TCB3 to generate an interrupt at about 250Hz. Every name of the interrupt service routine takes the subsequent column low within the keyboard matrix, and it then checks to see if any of the 4 row inputs has been pulled low by the urgent of a push button. If that’s the case, the button’s place is regarded up in the important thing desk Keymap[] to translate it to the ASCII code of the important thing. This additionally takes into consideration the state of the SHIFT and META keys, that are related to devoted inputs.

A keyboard buffer buffers a full display of textual content, so you should use the DEL key to delete characters and proper typing errors. The road editor consists of parenthesis matching which mechanically highlights matching brackets in inverse video as you kind in a program.

Putting in a bootloader

To program the Lisp Badge I like to recommend utilizing Spence Konde’s DxCore on GitHub.

Step one is to put in a bootloader utilizing a UPDI programmer. I used a SerialUPDI programmer, primarily based on a 3.3V FTDI USB-to-serial converter. As a result of the show is barely tolerant of three.3V you must energy the Lisp Badge from 3.3V whereas programming, or do the programming earlier than connecting the show to the board.

Select the AVR DB-series (Optiboot) possibility beneath the DxCore heading on the Board possibility on the Instruments menu. Examine that the next choices are set as follows (depart different choices at their defaults):

Chip: “AVR128DB48”
Clock Velocity: “24MHz inside”

Bootloader Serial Port (Bootloader burn req’d): “USART0 (default pins): TX PA0, RX PA1”

Set the Programmer possibility as acceptable for the UPDI programmer you might be utilizing. Then select Burn Bootloader.

Importing the Lisp Badge code

The subsequent step is to put in the Lisp Badge code through the serial connection, utilizing the bootloader you’ve gotten simply put in. Plug a 3.3V FTDI USB-to-serial converter into the FTDI connector on the PCB. I used the SparkFun FTDI Fundamental Breakout [11].

Go away the DxCore choices set as described above, and select the USB port from the Port submenu. Then select Add from the Sketch menu to add uLisp.

Be aware that this stage will fail if you happen to did not set the Bootloader Serial Port accurately within the earlier step, and you may want to return and repeat that step with the proper setting.

You need to then be capable to select Serial Monitor from the Instruments menu within the Arduino IDE, and kind Lisp instructions on the uLisp immediate.

Sources

Get the most recent Lisp Badge LE supply from GitHub, along with the Eagle information for the PCB so you can also make your self a board, at: Lisp Badge LE.

Or order a board from PCBWay right here: Lisp Badge LE.


  1. ^ 2.13″ 122*250 E-paper ink screen TFT Module on AliExpress.
  2. ^ Reverse Mount Tactile Switch Buttons on Adafruit.
  3. ^ Reverse Mount Tactile Switch Buttons on The Pi Hut.
  4. ^ FTDI Basic Breakout 3.3V on Sparkfun.
  5. ^ Kingbright KPTL-3216QBC on Farnell.com.
  6. ^ Square Wave External Piezo Buzzer on RS On-line.
  7. ^ KMTG1102-A1 Piezo Buzzer on RS On-line.
  8. ^ Coin Cell Battery Holder – 20mm (SMD) on SparkFun.
  9. ^ Coin Cell Battery Holder – 20mm (SMD) on Proto-PIC.
  10. ^ ST7302 Datasheet obtain from GitHub.
  11. ^ FTDI Basic Breakout 3.3V on SparkFun.


blog comments powered by

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top