Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Cascading MAX7219 LED Matrix Display

Image of Arduino UNO Controlled Cascading MAX7219 LED Matrix Display

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller connected to a series of MAX7219 8x8 LED Matrix modules. The Arduino UNO controls the LED matrices using a software-implemented SPI communication protocol. The matrices are daisy-chained together, allowing for control over a large display area using a minimal number of microcontroller pins. The circuit is designed to display patterns or images across the LED matrices.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the main controller for the LED matrices, sending data and control signals.
  • Pins Used: 5V, GND, D10 (CS), D11 (DIN), D12 (CLK).

MAX7219 8x8 LED Matrix Modules

  • Description: An 8x8 LED Matrix module controlled by the MAX7219 driver.
  • Purpose: Displays the visual output as instructed by the Arduino UNO.
  • Pins Used: VCC, GND, CS, CLK, DIN, CS(OUT), CLK(OUT), DOUT, VCC(OUT).

Wiring Details

Arduino UNO

  • 5V to VCC on the first MAX7219 LED Matrix.
  • GND to GND on the first MAX7219 LED Matrix.
  • D12 to CLK on the first MAX7219 LED Matrix.
  • D11 to DIN on the first MAX7219 LED Matrix.
  • D10 to CS on the first MAX7219 LED Matrix.

MAX7219 8x8 LED Matrix Modules

  • VCC connected to 5V from the Arduino UNO and VCC(OUT) to the next matrix's VCC.
  • GND connected to GND from the Arduino UNO and GND to the next matrix's GND.
  • CS connected to CS(OUT) from the previous matrix (except the first one, which is connected to the Arduino).
  • CLK connected to CLK(OUT) from the previous matrix (except the first one, which is connected to the Arduino).
  • DIN connected to DOUT from the previous matrix (except the first one, which is connected to the Arduino).

Documented Code

// This version uses bit-banged SPI.
// If you see tearing (jagged edges on the circles) try the version
// which uses AVR's hardware SPI peripheral:
// https://wokwi.com/arduino/projects/318868939929027156

#define CLK 12
#define DIN 11
#define CS  10
#define X_SEGMENTS   4
#define Y_SEGMENTS   4
#define NUM_SEGMENTS (X_SEGMENTS * Y_SEGMENTS)

// a framebuffer to hold the state of the entire matrix of LEDs
// laid out in raster order, with (0, 0) at the top-left
byte fb[8 * NUM_SEGMENTS];

void shiftAll(byte send_to_address, byte send_this_data)
{
  digitalWrite(CS, LOW);
  for (int i = 0; i < NUM_SEGMENTS; i++) {
    shiftOut(DIN, CLK, MSBFIRST, send_to_address);
    shiftOut(DIN, CLK, MSBFIRST, send_this_data);
  }
  digitalWrite(CS, HIGH);
}

void setup() {
  Serial.begin(115200);
  pinMode(CLK, OUTPUT);
  pinMode(DIN, OUTPUT);
  pinMode(CS, OUTPUT);

  // Setup each MAX7219
  shiftAll(0x0f, 0x00); //display test register - test mode off
  shiftAll(0x0b, 0x07); //scan limit register - display digits 0 thru 7
  shiftAll(0x0c, 0x01); //shutdown register - normal operation
  shiftAll(0x0a, 0x0f); //intensity register - max brightness
  shiftAll(0x09, 0x00); //decode mode register - No decode
}

void loop() {
  // ... (loop code omitted for brevity)
}

void set_pixel(uint8_t x, uint8_t y, uint8_t mode) {
  byte *addr = &fb[x / 8 + y * X_SEGMENTS];
  byte mask = 128 >> (x % 8);
  switch (mode) {
    case 0: // clear pixel
      *addr &= ~mask;
      break;
    case 1: // plot pixel
      *addr |= mask;
      break;
    case 2: // XOR pixel
      *addr ^= mask;
      break;
  }
}

void safe_pixel(uint8_t x, uint8_t y, uint8_t mode) {
  if ((x >= X_SEGMENTS * 8) || (y >= Y_SEGMENTS * 8))
    return;
  set_pixel(x, y, mode);
}

void clear() {
  byte *addr = fb;
  for (byte i = 0; i < 8 * NUM_SEGMENTS; i++)
    *addr++ = 0;
}

void show() {
  // ... (show function code omitted for brevity)
}

Code Explanation

  • Constants: Define the pins used for communication and the dimensions of the LED matrix setup.
  • Framebuffer: An array to hold the state of the LEDs.
  • shiftAll(): Sends data to all MAX7219 modules.
  • setup(): Initializes the Arduino pins and configures the MAX7219 modules.
  • loop(): Contains the main logic for updating the LED matrix display (code omitted for brevity).
  • set_pixel(): Sets the state of a single pixel in the framebuffer.
  • safe_pixel(): A wrapper for set_pixel() that checks for out-of-bounds coordinates.
  • clear(): Clears the framebuffer.
  • show(): Sends the framebuffer to the LED matrices (code omitted for brevity).