MAX7219 8-Digit Display Module

These 8-digit seven-segment display modules are available very cheaply from sites such as eBay, AliExpress [1], and Banggood and are ideal for displaying a value from a sensor or calculation:

MAX7219.jpg

They are based on the MAX7219 display driver [2] and are easy to control using SPI.

The MAX7219 is specified as operating from 4.0 V to 5.5 V, but it seems to work fine from 3.3 V. For a brighter display when using it with a 3.3 V board connect VCC on the MAX7219 to the +5 V pin on the board.

Connecting the display

Connect the display using the appropriate SPI pins as follows:

VCC +5V
GND GND
DIN MOSI
CS Enable
CLK SCK

For details of which pins are used for the SPI interface on different processors see Language reference: with-spi.

You can use any suitable pin as the Enable pin; specify it as follows:

(defvar en 10)

Display command

Every command written to the display is a 16-bit word, consisting of an address or command code followed by a data value:

(defun cmd (a d)
  (with-spi (str en)
    (write-byte a str)
    (write-byte d str)))

Initialising the display

The following routine on turns on the display and sets the brightness; the parameter can be from 0 (dimmest) to 15 (brightest):

(defun on (bri)
  (cmd #xF 0)    ; Test mode off
  (cmd #x9 #xFF) ; Decode segments
  (cmd #xB 7)    ; 8 digits
  (cmd #xC 1)    ; Enable display
  (cmd #xA bri))

Defining the segment definitions

The following list gives the segment definitions for the digits 0 to 9, the hexadecimal digits A to F, and space and minus:

(defvar seg '(#x7e #x30 #x6d #x79 #x33 #x5b #x5f #x70 #x7f 
              #x7b #x77 #x1f #x4e #x3d #x4f #x47 #x00 #x01))

Clearing the display

This routine clr clears the display:

(defun clr ()
  (dotimes (d 8) (cmd (1+ d) 0)))

Displaying digits

Finally this routine put writes eight digits to the display:

(defun put (dp &rest dig)
  (dotimes (d 8)
    (cmd (1+ d) 
         (+ (nth (nth (- 7 d) dig) seg) 
            (if (= dp (- 7 d)) #x80 0)))))

The first parameter specifies the decimal point position, from 0 (leftmost digit) to 7 (rightmost digit). Set it to 8 for no decimal point.

The remaining eight parameters specify the number to show on each display. For example, to display "3.1415926" give the command:

(put 0 3 1 4 1 5 9 2 6)

and to display "FACE-OFF" give:

(put 8 15 10 12 14 17 0 15 15)

  1. ^ MAX7219 8 Digit LED Display on AliExpress.
  2. ^ MAX7219 Datasheet on MaximIntegrated.