RaspberryPi: Connecting to an Led Matrix with MAX7219.

My Setup

  • Raspberry Pi Model 3
  • Raspbian Jessie (PIXEL)
  • 8×8 LED matrix Max7219
  • Breadboard
  • Selection of wires/connectors
  • Mouse, Keyboard & Monitor

So It Begins

The Max7219 LED matrix was one of our first projects together, to start with we only had the one 8×8 Led Matrix, since writing this article we have managed to cascade 4 8×8 matrix units together to create a scrolling message board type of display.

Finding Information

Our initial search lead us to various websites, many of which seemed to provide slightly different information. Eventually we landed up at the github pages of Richard Hull (Link), he has produced everything needed to get the LED Matrix working using the MAX7219 SPi driver on your Raspberry Pi.

Wiring The Matrix

To wire the Max7219 LED matrix to our RPi we connected them directly to the GPIO pins as follows:

  1. VCC (+5v) > GPIO Header Pin 2 (5v Out)
  2. GND (-Ground) > GPIO Header Pin 6 (GND)
  3. DIN (Data In) > GPIO Header Pin 19 (GPIO 10 MOSI)
  4. CS (Chip Select) > GPIO Header Pin 24 (GPIO 8 SPI CS0)
  5. CLK (Clock) > GPIO Header Pin 23 (GPIO 11 SPI CLOCK)

After our inital trials we began to make use of a breadboard in order to neaten things up and provide a base for the Matrix to sit in.

Installing The Matrix

SPI Needs to be enabled in your Raspberry pi;

spi-menu

  • Run sudo raspi-config .
  • Use the down arrow to select 9 Advanced Options.
  • Arrow down to A6 SPI .
  • Select yes when it asks you to enable SPI,
  • Also select yes when it asks about automatically loading the kernel module.
  • Use the right arrow to select the button.
  • Select yes when it asks to reboot.

Installing the items needed to make the Max7219 run on your Raspberry Pi is pretty straight forward, this can be done via terminal or remotely with utilities like Putty, as always you should make sure that your OS is up-to-date by running the first 2 commands below before anything else!

  • sudo apt-get update && sudo apt-get upgrade
  • sudo pip install spidev
  • git clone https://github.com/rm-hull/max7219.git
  • cd max7219
  • sudo python setup.py install

Something that tripped us up with getting this to work is whilst scanning (and skipping text) to get to the answers we needed we missed the part that says that SPI needs to be enabled on your RPi in order for the RPi to be able to communicate with the LED Matrix, it is an easy to fix but a pain at night when your tired and trying to figure out what’s gone wrong.

Running The Matrix

Now all that is left to do is run the Matrix 🙂

  • cd  /max7219/
  • cd /examples/
  • sudo python matrix_test.py

Note: the matrix_test.py script is pretty long, pressing CTRL + C should allow you to exit out at any time.

After you have tested the Max7219 LED matrix and it is working you can use the code found within the test script to create your own message. Heres the simple code that we use to display a message:

###### START CODE ######

import max7219.led as led
import time
from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT
from random import randrange

device = led.matrix(cascaded=1)

device.show_message(“A Boy & His Code”)
time.sleep(1)

device.flush()

###### END CODE ######

Advertisement

3 thoughts on “RaspberryPi: Connecting to an Led Matrix with MAX7219.

Add yours

  1. Following this guide, I am encountering an odd situation: once I’ve wired the MAX7219(CNG +1608) to the Pi (model 3B plus) then turn on the power, all 64 LEDs on the display light up and stay lit. I’ve tried a few different MAX7219s (I purchased a few – but starting out with just one to begin with for sanity) – but no luck. I have the VCC, GND, DIN,CS, and CLK wired into the PI’s GPIO as described in this article. Do I perhaps need to breadboard this and alter the connections (e.g., add resistance, a capacitor, etc.)?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by WordPress.com.

Up ↑

techtutorialsx

Lots of programming, IoT and technology tutorials

EngineerDog.com

Homepage for Michael's Science Projects & Maker Tips

BrainsChild

Let's Read, Create and Deploy

Fabien's Bit Bucket

Voiding warranties since 1980

Hackaday

Fresh hacks every day

%d bloggers like this: