HT16K33 Alphanumeric Display
The Adafruit Quad Alphanumeric Display [1] can display four 14-segment 0.54" alphanumeric characters, and it includes a HT16K33 driver [2] allowing it to be controlled by I2C. It's available in a variety of colours.
You can select from eight I2C addresses using solder links on the back of the board; the default I2C address with no links is #x70 or 112.
This program will also work with my Eight-Character Alphanumeric Display.
Defining the characters
The following list *codes* defines the 64 characters from space (ASCII code 32) to '_' (ASCII code 95):
(defvar *codes* '(#x0 #x6 #x220 #x12CE #x12ED #xC24 #x235D #x400 #x2400 #x900 #x3FC0 #x12C0
#x800 #xC0 #x0 #xC00 #xC3F #x6 #xDB #x8F #xE6 #x2069 #xFD #x7 #xFF #xEF #x1200 #xA00 #x2400
#xC8 #x900 #x1083 #x2BB #xF7 #x128F #x39 #x120F #xF9 #x71 #xBD #xF6 #x1200 #x1E #x2470 #x38
#x536 #x2136 #x3F #xF3 #x203F #x20F3 #xED #x1201 #x3E #xC30 #x2836 #x2D00 #x1500 #xC09 #x39
#x2100 #xF #xC03 #x8))
Although the display can in theory show lower-case letters, they are not very readable, so these routines only support the upper-case characters.
Initialising the display
The routine on turns on the display and sets the brightness to a value of between 0 and 15:
(defun on (bri) (with-i2c (str #x70) (write-byte #x21 str) (restart-i2c str) (write-byte (+ bri #xe0) str) (restart-i2c str) (write-byte #x81 str)))
Displaying characters
You display a character by writing two bytes to the display to specify which segments are lit. The routine display writes the segment codes for a character x to the stream str as two bytes:
(defun display (x str) (if (>= x #x60) (setq x (- x #x20))) (write-byte (nth (- x 32) *codes*) str) (write-byte (ash (nth (- x 32) *codes*) -8) str))
Finally, show displays a four-character text string on the display:
(defun show (txt) (with-i2c (str #x70) (write-byte #x00 str) (dotimes (x 4) (display (char-code (if (< x (length txt)) (char txt x) #\space)) str))))
For example, the following command displays LISP:
(show "LISP")
To use this with my Eight-Character Alphanumeric Display, in show change the 4 to 8.
For a routine to display a scrolling text message see Scrolling text display.
- ^ Quad Alphanumeric Display - Red 0.54" Digits with I2C Backpack on Adafruit.
- ^ HT16K33 Datasheet on Adafruit.