Driving the Max7219 with the Raspberry Pi

The max7219 lets us control lots and lots of LEDs using just a few Raspberry Pi pin-outs. No hassles with multiplexing, latching, refreshing or using up all your outputs – it handles everything for us. We just send commands to the max7219 and we can control up to 64 LEDs or eight seven (8 including the decimal point?) segment displays, you can even chain multiple max7219s together to drive loads more. All this via just a few pins.

Driving the Max7219 with the Raspberry Pi

Bit banging the max7219

Both the Raspberry Pi and the max7219 support SPI (Serial Peripheral Interface?), a good idea then to the get the RPi to talk to a max7219 via its very own SPI interface, right? It didn’t work. I enabled SPI easily enough, by default its turned off, and I even managed to send and receive data, I think. I just couldn’t seem to get the max7219 to do anything apart from tease me with an ‘E’ (error?) on the 7 seg display.

Easier, I thought, to just ignore the hardware SPI and connect 3 normal digital GPIO pins to the max7219 and bit bang directly.

Connecting pins 1 (data), 12 (load) and 13 (clock) to the RPi GPIO pins 17, 23 and 22.
Pins 4 and 9 to RPi Ground.
Pin 19 to RPi’s 5V along with pin 18 via a resistor of your choice depending on your LED.

It’s then a matter of sending commands to the max7219 via the data in, clock and load line.

For instance, to display the number 4 on digit 1 we would send the command 0x104 (0x01 : use digit 1, 0x04 : display the number 4). Which might look something like this :

Set LOAD to 1.
Send 16 bits command and data (0x104 = 0000000100000100), and for each binary digit we : set CLOCK to 0; send the binary digit, set CLOCK to 1.
To finish, set LOAD to 0 then set LOAD to 1.

Driving the Max7219 with the Raspberry Pi SchematicAt this point it might be worth mentioning that the max7219 can work in two modes, BCD decode on or off. With BCD on we can just send the number we want to appear on the 7seg display to the max7219 and it will display it as shown above. As well as digits 0 to 9, 10 to 15 correspond to -, E, H, L, P and blank.

 

For more detail: Driving the Max7219 with the Raspberry Pi

Scroll to Top
Read previous post:
An elegant, stacking, Real Time Clock for Raspberry Pi

If you want to build a good Real Time Clock for your Raspberry here's the tutorial you were looking for!...

Close