The MAX7219 module - LED matrix 8x8

published: 21 November 2024 / updated 21 November 2024

Lire cette page en français

 

article: 05 nov. 2019 / mis à jour 24 nov. 2019

Dependancys

To use the MAX7219 module via the SPI interface, you must download and compile the code:
  Words to drive the SPI module on the ATmega2560

The 8x8 LED matrix

Here is our 8x8 LED matrix:

The 8x8 LED matrix

The display consists of 8 rows of 8 LEDs, for a total of 64 LEDs.

On the back of the display, 5 connectors on the right and 5 connectors on the left. All connectors have the same indications, except the 3rd connector which is marked DIN on the right, DOUT on the left.

Meaning of the connectors:

With the only DIN, CS and CLK connectors we have to manage the 64 LEDs of this display ...

Features of the 8x8 display

If you only use one 8x8 LEDs display on your ARDUINO board, the power supply USB may be sufficient. But it is strongly recommended to feed the display via a separate 5 Volt power supply.

The GND connector of the 8x8 LEDs display must be connected to a GND terminal of the ARDUINO card.

The display is controlled by a circuit referenced MAX7219. This component has of 2x eight parallel outputs managing the matrix of LEDs. It also has an interface of Serial Peripheral Interface SPI serial communication interface will see the features further.

Organization of the matrix 8x8 LEDs:

Organisation des LEDs de la matrice

No indication on the display can determine in which direction to orient this display.

Some articles on the Internet show that it is possible to serialize several 8x8 LEDs displays:

Serial connection of two 8x8 matrices

Having only one 8x8 LED display, we can not test the connection of several 8x8 LED arrays in series.

We will consider that the bottom of the display corresponds to the input connectors, placed at the bottom. The five output connectors are placed at the top.

Connection to the ARDUINO board

8x8 LED
matrix
ARDUINO
VCC+5V
GNDGND
DINMOSI
CSSS
CLKSCK
DOUT*MISO

* optional - DOUT output is connected:

The MAX7219 chip

It's a chip built into our 8x8 LED display.

The MAX7219 chip divides a set of 64 LEDs into eight columns (“digits”) of eight LEDs each. The columns are numbered 1 through 8, and each LED within a column is represented by a single bit in that column’s register.

Specification of LED Matrix

Operating Voltage: DC 4.7V – 5.3V

Typical Voltage: 5V

Operating Current: 320mA

Max Operating Current: 2A

Operating Temperature: 0 ℃ – 50 ℃

Typical Temperature: 25 ℃

Hardware Installation

Example of connecting the MAX7219 module to an ARDUINO MEGA board:

connection to an ARDUINO MEGA card

The power supply of the MAX7219 module must be carried out in preference to a 5-volt power supply separated from that of the ARDUINO card.

Organization of the matrix

Each row corresponds to an address. Each address can receive a byte in the hexadecimal interval [00..ff].

Each column corresponds to a bit in the byte transmitted as data.

organization of the 8x8 matrix

So, the lighting of a row will be done by transmitting two bytes:

Serial-Data Format (16 Bits)

Here's how addr data is organized:

D15D14D13D12 D11D10D9D8 D7D6D5D4 D3D2D1D0
XXXX ADDRESS MSB --- DATA --- LSB

Les adresses $0d et $0e ne sont pas exploitées.

Here are the actions performed by the addresses addr:

REGISTER ADDRESS HEX
CODE
D15
D12
D11D10D9D8
No-OpX 0000 $00
Digit 0X 0001 $01
Digit 1X 0010 $02
Digit 2X 0011 $03
Digit 3X 0100 $04
Digit 4X 0101 $05
Digit 5X 0110 $06
Digit 6X 0111 $07
Digit 7X 1000 $08
Decode ModeX 1001 $09
IntensityX 1010 $0a
Scan LimitX 1011 $0b
ShutdownX 1100 $0c
 
Display TestX 1111 $0f

Here are the words to manage the 8x8 LED matrix via the MAX7219 module.

The word max7219.send passes two bytes to the MAX7219 module:

: max7219.send ( c1 c2 -- ) 
    mSS1 slave.select 
    swap spi.csend spi.csend  
    mSS1 slave.deselect 
  ; 

The words disp.normal and disp.shutdown respectively allow to use the normal or disabled display mode:

: disp.normal   ( -- )  
    $0c $01 max7219.send ; 
: disp.shutdown ( -- )  
    $0c $00 max7219.send ; 

The words disp.test.on and disp.test.off allow you to activate or disable the test mode of the LEDs:

: disp.test.on  ( -- )  
    $0f $01 max7219.send ; 
: disp.test.off ( -- )  
    $0f $00 max7219.send ; 
MODE ADDRESS
CODE
REGISTER DATA
D7D6D5D4 D3D2D1D0
Shutdown Mode XXXXXXXX0
Normal Operation XXXXXXXX1

The word disp.no.op has no action. It is used in the case of linked MAX7219 modules.

: disp.no.op      ( -- )     
    $00 $00  max7219.send ; 

The word disp.intensity is used to set the intensity of the LEDs in normal display. This setting affects all the LEDs of the 8x8 matrix.

: disp.intensity  ( c -- )   
    $0a swap max7219.send ; 

The word disp.decode is used to select the decoding mode of the MAX7219 module.

: disp.decode     ( c -- )   
    $09 swap max7219.send ; 

The word disp.scan.limit limits the action to only certain rows of LEDs.

: disp.scan.limit ( c -- )   
    $0b swap max7219.send ; 
SCAN LIMIT REGISTER DATA HEX
CODE
D7D6D5D4D3D2D1D0
Display digit 0 only XXXXX 000 $00
Display digits 0 & 1 XXXXX 001 $01
Display digits 0 1 2 XXXXX 010 $01
Display digits 0 1 2 3 XXXXX 011 $03
Display digits 0 1 2 3 4 XXXXX 100 $04
Display digits 0 1 2 3 4 5 XXXXX 101 $05
Display digits 0 1 2 3 4 5 6 XXXXX 110 $06
Display digits 0 1 2 3 4 5 6 7 XXXXX 111 $07

And finally, the word disp.set.digit

: disp.set.digit  ( cbits cdigit -- )  
    swap max7219.send ; 

This word is used in the display test examples below.

Some display tests

The word disp-test-1 is used to test the display of the LEds of the matrix 8x8:

: disp-test-1 ( -- ) \ all LEDs on full, 232mA needed 
    spi.init 
    disp.test.on 
    begin key? until 
    disp.test.off 
    spi.close 
  ; 

Here is what gives the execution of the word disp-test-1:

Execution is interrupted by pressing a key on the keyboard.

The word disp-test-2 turns on the 4 left LEDs of the first row:

: disp-test-2 ( -- ) \ left 4 LEDs on first row, 42mA needed 
    spi.init 
    disp.normal 
    $03 disp.intensity 
    $00 disp.scan.limit 
    $f0 $01 disp.set.digit 
    begin key? until 
    disp.shutdown 
    spi.close 
  ; 

Here is what gives the execution of the word disp-test-2:

Execution is interrupted by pressing a key on the keyboard.

The word disp-test-3 displays a smiley character:

: disp-test-3 ( -- ) \ draw face, 18mA needed 
    spi.init 
    disp.normal 
    $01 disp.intensity 
    $07 disp.scan.limit 
    $00 disp.decode 
    %00000000 $01 disp.set.digit 
    %01100110 $02 disp.set.digit 
    %00000000 $03 disp.set.digit 
    %00011000 $04 disp.set.digit 
    %00011000 $05 disp.set.digit 
    %10000001 $06 disp.set.digit 
    %01000010 $07 disp.set.digit 
    %00111100 $08 disp.set.digit 
    begin key? until 
    disp.shutdown 
    spi.close 
  ; 

Here is what gives the execution of the word disp-test-3:

Execution is interrupted by pressing a key on the keyboard.