Raspberry Pi LED Matrix Library – Installation for multiline m x n MAX7219 LED Matrices

12. August 2014

In this Tutorial I will show you how to use the library for multilined MAX7219 Matrices I wrote (improved and extended version of JonA1961’s MAX7219array https://github.com/JonA1961/MAX7219array )




If you buy LED Dot Matrices, you should mind that these must be quadratic.

I wrote an article (german) about how to solder a MAX7219 Matrix.



To use this LED Dot Matrices you have to install the python spi library. If you already have done this you can skip this step.

If you haven’t it installed yet, i would recommend to follow this instructions: http://www.100randomtasks.com/simple-spi-on-raspberry-pi


Setup of the Matrices

Once you have soldered all LED Matrices you can connect them. For working correctly it is important to connect them like in the picture below. The first module is bottom left (seen from the front side), the next one above it. When one column is finished  you set the next module on the right side at the bottom, the next one above it and so on.


Front view (matrices are numbered)

Back view (Jumper cables from Matrix 1 go to the RPi)

Each Matrix has these Pins:

Right: CLK – CS – DIN – GND – VCC

Left: CLK – CS – DOUT – GND – VCC

The DOUT Pin of the previous matrix is connected with DIN of the following. The other Pins are also connected.

The Pins of the first Matrix are connected to the Raspberry Pi as follows:


Installing library

I created a GitHub repository, you can download it from there (make sure you have installed the github client):

git clone https://github.com/tutRPi/multilineMAX7219.git && cd multilineMAX7219

In this directory are two important files:

multilineMAX7219.py – This is the main file, which contains all functions

multilineMAX7219_fonts.py – This file contains the letters and symbols of the different fonts. If you want to add some fonts, you should edit this file.


It is important to change the multilineMAX7219.py file (Line 113/114) and set your individual MATRIX_WIDTH and MATRIX_HEIGHT.


Demo Code

To run a demo you can type

python multilineMAX7219_demo.py

and see the different effects.


In my opinion the graphic functions are espacially interesting on multiline displays.
I made an easy site where you can draw images and display them on your LED Matrices:

The site you can find here.

As you see the code for the Raspberry Pi Logo (on 3×3 matrices) is given. I can import it in python:

logo = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,1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0,0,0,0,0,0]]

And now you can draw it with


For more details look into the multilineMAX7219_demo.py file and multilineMAX7219.py where all functions are described.


I made an example video (this is a short version of the demo file):

Leave a Comment

Your email address will not be published.

Blog abonnieren

Abonniere Tutorials-RaspberryPi, um kein Tutorial mehr zu verpassen!