Random Nerd Tutorials
Shares

Guide for 8×8 Dot Matrix MAX7219 with Arduino + Pong Game

Shares

The dot matrix that we’re going to use in this guide is a 8×8 matrix which means that it has 8 columns and 8 rows, so it contains a total of 64 LEDs.

The MAX7219 chip makes it easier to control the dot matrix, by just using 3 digital pins of the Arduino board.

I think the best option is to buy the dot matrix with the MAX7219 chip as a module, it will simplify the wiring. You can get this module on ebay for less than 2$.

dotmatrixphoto

You can control more than one matrix at a time. For that you just need to connect them to each other, as they have pins in both sides to extend the dot matrix.

Parts required

For this guide you’ll need:

Pin Wiring

You only need to connect 5 pins from the dot matrix to your Arduino board. The wiring is pretty straightforward:

Dot matrix pin Wiring to Arduino Uno
GND GND
VCC 5V
DIN Digital pin
CS Digital pin
CLK Digital pin

How to control the dot matrix with Arduino

For making it easier to control the dot matrix, you need to download and install in your Arduino IDE the LedControl library. To install the library follow these steps:

  1. Click here to download the LedControl library. You should have a .zip folder in your Downloads
  2. Unzip the .zip folder and you should get LedControl-master folder
  3. Rename your folder from LedControl-master to LedControl
  4. Move the LedControl folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Using the LedControl library functions

The easiest way to display something on the dot matrix is by using the functions setLed(), setRow() or setColumn(). These functions allow you to control one single led, one row or one column at a time.

Here’s the parameters for each function:

setLed(addr, row, col, state)

  • addr is the address of your matrix, for example, if you have just 1 matrix, the int addr will be zero.
  • row is the row where the led is located
  • col is the column where the led is located
  • state
    • It’s true or 1 if you want to turn the led on
    • It’s false or 0 if you want to switch it off

setRow(addr, row, value)

setCol(addr, column, value)

Index

As previously stated, this matrix has 8 columns and 8 rows. Each one is indexed from 0 to 7. Here’s a figure for better understanding:

index

If you want to display something in the matrix, you just need to know if in a determined row or column, the LEDs that are on or off.

For example, if you want to display a happy face, here’s what you need to do:

faces

Code

Here’s a simple sketch that displays three types of faces: a sad face, a neutral face and a happy face. Upload the following code to your board:

In the end, you’ll have something like this:

gif_face_final

Pong Game

The pong game that you’re about to try was created by Alessandro Pasotti.

For the pong game, you just need to add a 1k ohm potentiometer to the previous schematic. Assemble the new circuit as shown below:

pongping_bb

Code

Then, upload the following code to your Arduino board:

Demonstration

Here’s the final demonstration of me playing the pong game. Have fun!

gif_game_f

Wrapping up

Have you ever used the dot matrix in your Arduino Projects?

Let me know by leaving a comment below.

If you like this post probably you might like my next ones (click here to subscribe my blog). Thanks for reading,

Rui

Leave a Comment:

Add Your Reply