8x8 Dot Matrix Display (MAX7219) Β· Astro Tech Blog

8x8 Dot Matrix Display (MAX7219)

The 8x8 dot matrix display consists of 64 LEDs arranged in an 8-row by 8-column grid. Each LED can be individually controlled to display characters, symbols, and simple graphics. The MAX7219 is a compact, serial-input/common-cathode display driver that interfaces microcontrollers to 64 individual LEDs, handling multiplexing and current limiting internally. It communicates over a 3-wire SPI-compatible interface and can be daisy-chained to control multiple displays.

8x8 Dot Matrix Display (MAX7219)

For this interfacing you need the following components:

  • Arduino board (Uno, Nano, Mega, etc.)
  • MAX7219 8x8 dot matrix display module (single or daisy-chained)
  • Breadboard and jumper wires
  • USB cable to connect Arduino to your computer

Schematic

Connect the MAX7219 dot matrix module to the Arduino as follows:

MAX7219 Module        Arduino
-------------        -------
VCC           -->     5V
GND           -->     GND
DIN           -->     Digital Pin 11 (MOSI)
CS            -->     Digital Pin 10 (SS)
CLK           -->     Digital Pin 13 (SCK)

Most MAX7219 modules use a 5-pin header: VCC, GND, DIN, CS, CLK. Some modules label CS as LOAD or CS. The module operates at 5V and includes a decoupling capacitor and current-setting resistor.

Pin Map

Module PinNameArduino Connection
VCCPower5V
GNDGroundGND
DINData InPin 11 (MOSI on Uno/Nano)
CSChip Select (Load)Pin 10 (SS)
CLKClockPin 13 (SCK on Uno/Nano)

For Mega 2560: MOSI = Pin 51, MISO = Pin 50, SCK = Pin 52, SS = Pin 53. For Leonardo: MOSI = ICSP-4, SCK = ICSP-3, SS = any digital pin.

Daisy-chaining multiple modules

To connect multiple MAX7219 modules, wire them in series:

Module 1           Module 2           Module 3
VCC    -----5V-----VCC    -----5V-----VCC
GND    -----GND----GND    -----GND----GND
DIN    --Arduino 11-->     DIN  --din-->  DIN
CS     --Arduino 10-->     CS   --cs-->   CS
CLK    --Arduino 13-->     CLK  --clk-->  CLK

Connect DOUT of Module 1 to DIN of Module 2, DOUT of Module 2 to DIN of Module 3, and so on. The CS and CLK lines are shared in parallel across all modules.

Install necessary Library

Install the LedControl library by Eberhard Fahle via the Library Manager (Tools > Manage Libraries).

Alternatively, using arduino-cli:

arduino-cli lib install "LedControl"

For animated text and scrolling effects, install MD_Parola by MajicDesigns and its dependency MD_MAX72XX:

arduino-cli lib install "MD_Parola"
arduino-cli lib install "MD_MAX72XX"

This tutorial uses the LedControl library for its simplicity.

Code with complete explanation

This sketch demonstrates how to control the MAX7219 8x8 dot matrix display. It displays individual pixels, patterns, scrolling text, and animated faces.

#include <LedControl.h>

// Pin connections: DIN, CS, CLK, number of daisy-chained modules
LedControl lc = LedControl(11, 10, 13, 1);

// Custom bitmap: heart pattern (8 bytes = 8 rows)
const byte heart[8] = {
  B01100110,
  B11111111,
  B11111111,
  B11111111,
  B01111110,
  B00111100,
  B00011000,
  B00000000
};

// Custom bitmap: smiley face
const byte smiley[8] = {
  B00111100,
  B01000010,
  B10100101,
  B10000001,
  B10100101,
  B10011001,
  B01000010,
  B00111100
};

void setup()
{
  // Wake up the MAX7219 from power-saving mode
  lc.shutdown(0, false);

  // Set brightness (0 = min, 15 = max)
  lc.setIntensity(0, 8);

  // Clear the display
  lc.clearDisplay(0);
}

void loop()
{
  // 1. Turn on individual pixels
  for (int row = 0; row < 8; row++)
  {
    for (int col = 0; col < 8; col++)
    {
      lc.setLed(0, row, col, true);
      delay(30);
    }
  }

  lc.clearDisplay(0);
  delay(300);

  for (int row = 0; row < 8; row++)
  {
    for (int col = 0; col < 8; col++)
    {
      lc.setLed(0, row, col, false);
      delay(30);
    }
  }

  delay(300);

  // 2. Display custom bitmaps
  displayBitmap(heart);
  delay(1500);

  displayBitmap(smiley);
  delay(1500);

  // 3. Animate a bouncing pixel
  bouncePixel();
}

void displayBitmap(const byte bitmap[8])
{
  for (int row = 0; row < 8; row++)
  {
    lc.setRow(0, row, bitmap[row]);
  }
}

void bouncePixel()
{
  int dx = 1, dy = 1;
  int x = 0, y = 0;

  for (int i = 0; i < 40; i++)
  {
    lc.clearDisplay(0);
    lc.setLed(0, y, x, true);

    x += dx;
    y += dy;

    if (x >= 7 || x <= 0) dx = -dx;
    if (y >= 7 || y <= 0) dy = -dy;

    delay(80);
  }
}

Code breakdown

  • #include <LedControl.h> β€” includes the LedControl library for MAX7219 communication.
  • LedControl lc(11, 10, 13, 1) β€” creates a LedControl instance. Parameters: DIN pin, CS pin, CLK pin, number of daisy-chained modules (1 in this example).
  • lc.shutdown(0, false) β€” wakes the MAX7219 from its default power-saving mode. The first argument (0) is the module index.
  • lc.setIntensity(0, 8) β€” sets brightness to a medium level (0–15).
  • lc.clearDisplay(0) β€” turns off all LEDs on module 0.
  • lc.setLed(0, row, col, state) β€” turns a single LED at (row, col) on (true) or off (false).
  • lc.setRow(0, row, value) β€” writes an entire row at once using an 8-bit byte value (each bit corresponds to a column).
  • B01100110 β€” binary literal used to define row patterns for custom bitmaps. A 1 bit turns the LED on, 0 turns it off.

Displaying characters and numbers

The LedControl library can write ASCII characters directly:

// Display a character at column offset
lc.setChar(0, 0, 'A', true);  // module, column offset, char, dp (decimal point)

// Write a raw digit (0-9) with no character map translation
lc.setDigit(0, 0, 7, false);  // module, column offset, digit (0-9), dp

Using MD_Parola for scrolling text

For scrolling text and animations, use the MD_Parola library:

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4  // 4 daisy-chained modules = 32 columns

#define CS_PIN 10

MD_Parola display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void setup()
{
  display.begin();
  display.setIntensity(8);
  display.displayText("HELLO!", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}

void loop()
{
  if (display.displayAnimate())
  {
    display.displayReset();
  }
}

Steps to perform this interfacing

  1. Connect the MAX7219 dot matrix module to the Arduino as shown in the schematic.
  2. Install the LedControl library via the Library Manager.
  3. Copy the code into the Arduino IDE.
  4. If using multiple modules, change the fourth argument in LedControl(11, 10, 13, 1) to match your module count.
  5. Select the correct board and port (Tools > Board and Tools > Port).
  6. Upload the sketch to the Arduino.
  7. Observe the display β€” it will fill all LEDs, display a heart then a smiley, and finally animate a bouncing pixel.
  8. Adjust brightness by changing the value in setIntensity() (0–15).

Caution

  • The MAX7219 operates at 5V. Connecting it to 3.3V logic may result in unreliable operation. Use a level shifter if using a 3.3V Arduino board.
  • Do not connect or disconnect the module while the circuit is powered on β€” this can damage the MAX7219 driver IC.
  • The module’s current-setting resistor (typically R1, 10kΞ©) limits LED brightness. Using a lower value increases brightness but also increases current draw. The MAX7219 can source up to 500 mA total for all 64 LEDs.
  • If the display flickers or shows garbled patterns, check wiring length β€” long wires (over 30 cm) on the SPI lines can cause signal integrity issues. Use shorter wires or add 100Ξ© series resistors on DIN, CS, and CLK.
  • When daisy-chaining modules, ensure the DOUT of each module connects to the DIN of the next. The CS and CLK lines must be shared in parallel.
  • The MAX7219 enters shutdown mode (all LEDs off, minimal power draw) by default on power-up. The lc.shutdown(0, false) call is required to activate the display.
  • Each module draws approximately 30–50 mA when displaying a typical pattern and up to 500 mA at full brightness. For 4+ daisy-chained modules, use an external 5V power supply rather than powering through the Arduino 5V pin.