Cannot get images to scroll on Arduino and 8x8 matrices

I am hoping someone here can help me or point me in the right direction. I do not have a lot of experience in programming, but for the most part, I have been able to copy and paste and make the majority of my projects work, but this 8x8 matrix project is kicking my butt.

I have 4 8x8 Max72xx matrix displays hooked up together. I have tried numerous things but I cannot figure out how to get them to scroll the text. When I upload the sketch all the matrices display the exact same thing on all of them.

I believe this is the original code that I used from here

#include <LedControl.h>

const int DIN_PIN = 12;
const int CS_PIN = 10;
const int CLK_PIN = 11;

const byte IMAGES[][8] = {
{
  0b11111111,
  0b00000000,
  0b00000000,
  0b10000000,
  0b10000000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b11000000,
  0b11000000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b01100000,
  0b01100000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00110000,
  0b00110000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00011000,
  0b00011000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00001100,
  0b00001100,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000110,
  0b00000110,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000011,
  0b00000011,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000001,
  0b00000001,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000011,
  0b00000011,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000110,
  0b00000110,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00011000,
  0b00011000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b00110000,
  0b00110000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b01100000,
  0b01100000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b11000000,
  0b11000000,
  0b00000000,
  0b00000000,
  0b11111111
},{
  0b11111111,
  0b00000000,
  0b00000000,
  0b10000000,
  0b10000000,
  0b00000000,
  0b00000000,
  0b11111111
}};
const int IMAGES_LEN = sizeof(IMAGES)/8;

LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN);

void setup() {
  display.clearDisplay(0);
  display.shutdown(0, false);
  display.setIntensity(0, 5);
}

void displayImage(const byte* image) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      display.setLed(0, i, j, bitRead(image[i], 7 - j));
    }
  }
}

int i = 0;

void loop() {
  displayImage(IMAGES[i]);
  if (++i >= IMAGES_LEN ) {
    i = 0;
  }
  delay(333);
}

Is there a way for me to update this to take advantage of multiple matrices or am I barking up the wrong tree? I would prefer to keep this code if possible because I would like to use the matrix editor to make the animations.

Thanks in advance.

I don't know what animation you want to do, but your current code has 2 errors.

1 in this line:
LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN);
you need to define how many modules you have.

If your project has 8 modules, it needs to be like this:
LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 8);

  1. This function i redo to use 8 modules:
void displayImage(const byte* image) {
  for (int k = 0; k < 8; k++) {
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        display.setLed(k, i, j, bitRead(image[i], 7 - j));
      }
    }
  }
}

Try your code modified:

Simulated at: https://wokwi.com/projects/396454087867262977

#include <LedControl.h>
const int DIN_PIN = 12;
const int CS_PIN = 10;
const int CLK_PIN = 11;
const byte IMAGES[][8] = {
  {
    0b11111111,
    0b00000000,
    0b00000000,
    0b10000000,
    0b10000000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b11000000,
    0b11000000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b01100000,
    0b01100000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00110000,
    0b00110000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00011000,
    0b00011000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00001100,
    0b00001100,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00000110,
    0b00000110,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00000011,
    0b00000011,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00000001,
    0b00000001,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00000011,
    0b00000011,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00000110,
    0b00000110,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00011000,
    0b00011000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b00110000,
    0b00110000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b01100000,
    0b01100000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b11000000,
    0b11000000,
    0b00000000,
    0b00000000,
    0b11111111
  }, {
    0b11111111,
    0b00000000,
    0b00000000,
    0b10000000,
    0b10000000,
    0b00000000,
    0b00000000,
    0b11111111
  }
};
const int IMAGES_LEN = sizeof(IMAGES) / 8;
LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 8);
//--------------------------------------------------------------------
void setup() {
  display.clearDisplay(0);
  display.shutdown(0, false);
  display.setIntensity(0, 5);
}
//--------------------------------------------------------------------
void displayImage(const byte* image) {
  for (int k = 0; k < 8; k++) {
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        display.setLed(k, i, j, bitRead(image[i], 7 - j));
      }
    }
  }
}
//--------------------------------------------------------------------
int i = 0;
void loop() {
  displayImage(IMAGES[i]);
  if (++i >= IMAGES_LEN ) {
    i = 0;
  }
  delay(333);
}

The code you posted works on wokwi.com ... here is the file for setup

diagram.json

{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": 95.5, "attrs": {} },
    {
      "type": "wokwi-max7219-matrix",
      "id": "matrix1",
      "top": -95.4,
      "left": -15.39,
      "attrs": { "chain": "1" }
    }
  ],
  "connections": [
    [ "matrix1:CS", "nano:10", "green", [ "h0" ] ],
    [ "matrix1:GND", "nano:GND.1", "black", [ "h0" ] ],
    [ "nano:5V", "matrix1:V+", "red", [ "v0" ] ],
    [ "nano:12", "matrix1:DIN", "green", [ "v0" ] ],
    [ "nano:11", "matrix1:CLK", "green", [ "v0" ] ]
  ],
  "dependencies": {}
}

dot

p.s. Your 11th matrix is missing. I filled it in here.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.