UNO R3 strange behaviour

Hello all,

please help to solve some confusion. The matter is - there is UNO R3 with MAX7219 controlled 4 8x8 LED matrices. Now upload simplest sketch based on LedControl library. And strange behavior occurs - everything works as expected right after compile and upload (it endlessly equally counts down digits from 9 to 0 simultaneously on all 4 segments) then unplug USB from comp then plug it back and it starts doing essentially the same but in a weird way like still counting 9 to 0, but on just 4th matrix, other 3 are remaining blank. And the weirdest thing is that it could be fixed (till the next UNO power off/on) just by opening Serial monitor in Arduino IDE (despite that there is no Serial communication in sketch at all) or by pressing Reset button on board. The sketch is a simplest one almost fully taken from library's example (attaching it). Anyone have any idea?

led_control.ino (1.19 KB)

I probably can't help you.

Your code

#include "LedControl.h"

LedControl lc = LedControl(11, 13, 10, 4);

const uint64_t IMAGES[] = {
  0x003c407c42423c00,
  0x003c42423c423c00,
  0x0004081020427e00,
  0x003c42423e023c00,
  0x003e40403e023e00,
  0x0040407e42424200,
  0x003c424038423c00,
  0x007e023c40423c00,
  0x0010101014181000,
  0x003c464a52623c00
};

const int IMAGES_LEN = sizeof(IMAGES) / 8;

unsigned long delaytime = 100;

void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0, 2);
  lc.clearDisplay(0);
  lc.shutdown(1, false);
  lc.setIntensity(1, 2);
  lc.clearDisplay(1);
  lc.shutdown(2, false);
  lc.setIntensity(2, 2);
  lc.clearDisplay(2);
  lc.shutdown(3, false);
  lc.setIntensity(3, 2);
  lc.clearDisplay(3);
}

void clear() {
  for (int i = 0; i < 4; i++)
    lc.clearDisplay(i);
}

void displayHexImage(uint64_t image) {
  for (int i = 0; i < 8; i++) {
    byte row = (image >> i * 8) & 0xFF;
    for (int j = 0; j < 8; j++) {
      lc.setLed(0, i, j, bitRead(row, j));
      lc.setLed(1, i, j, bitRead(row, j));
      lc.setLed(2, i, j, bitRead(row, j));
      lc.setLed(3, i, j, bitRead(row, j));
    }
  }
}

int k = 0;

void loop() {
  displayHexImage(IMAGES[k]);
  if (++k >= IMAGES_LEN ) {
    k = 0;
  }
  delay(500);
}

Please read How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum and pay special attention to point #7 about posting code using code tags.

Can you please provide a wiring diagram (including exact power wiring).

sterretje:
Can you please provide a wiring diagram (including exact power wiring).

Wired as this:

  • DIN to pin 11;
  • CLK to pin 13;
  • CS to pin 10;
  • VCC to 5V;
  • GND to GND.

The built-in LED is connected to pin 13 and may get used for a few seconds after power-up as part of the boot/download process. I would avoid it if possible.

Much has been written about mysterious behavior of the max7219 chip when the load pin is allowed to float during device initialisation .
For example: [SOLVED] pull-up or pull-down resistor on LOAD of MAX7219 - LEDs and Multiplexing - Arduino Forum

6v6gt:
Much has been written about mysterious behavior of the max7219 chip when the load pin is allowed to float during device initialisation .
For example: [SOLVED] pull-up or pull-down resistor on LOAD of MAX7219 - LEDs and Multiplexing - Arduino Forum

Thanks for that; I was wondering why @vaj4088 comment would not apply to other SPI communications.

And the weirdest thing is that it could be fixed (till the next UNO power off/on) just by opening Serial monitor in Arduino IDE (despite that there is no Serial communication in sketch at all) or by pressing Reset button on board.

Opening serial monitor causes a reset!

Power cycle is a reset as well :wink:

So what is the difference? A supply voltage that has settled?

Yes, I was also thinking along those lines. For some reason, 3 of the max chips are not receiving the instructions send by the setup() function. Maybe they are not quite ready. Maybe try a delay(100) at the beginning of setup().