MAX 7219 broken?

Hi guys,

I recently bought a cheap 7-segment MAX 7219 tube (similar to this). I wrote a simple code to test its functionality, however it doesn´t do what it should (count to 999) but show some random numbers and stops showing anything after a few seconds.

I am using ths code:

#include <LedControl.h>

LedControl lc = LedControl(8, 10, 9, 1);
unsigned long delaytime=100;

void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
  Serial.begin(9600);
  
}
int digit(int a,int b){
  lc.setDigit(0,a,b,false);
}

int digit_dp(int a,int b){
  lc.setDigit(0,a,b,true);
}

void chrono() {
  lc.clearDisplay(0);
  int a=0;
  int b=0;
  int c=0;
  

  for (int timer=0;timer<999;timer++){
    a = timer % 10;
    int timer1 = timer/10;
    b = timer1 % 10;
    int timer2=timer1/10;
    c= timer2;

    digit(0,c);
    Serial.println(c);
    delay(delaytime);
    digit(1,b);
    Serial.println(b);
    delay(delaytime);
    digit(2,a);
    Serial.println(a);
    delay(delaytime);
    digit(3,0);

    delay(500);
  }
}


  


void loop() {
  chrono();
}

(I inserted a Serial print for easier debugging).

I dont have much experience with Arduino and especially the MAX 7219 chip, so my question is: Is there anything wrong with my code? Or could the MAX 7219 7-segment tube simply be broken?

Thanks
David

777-Pilot:
so my question is: Is there anything wrong with my code? Or could the MAX 7219 7-segment tube simply be broken?

Your code is very difficult to read since you seem to like to use variables with anonymous names that don't reflect their role.

I know what your code says about how your device is connected but is it connected the way the code says?

Hi, thanks for your answer.

Yes, the MAX 7219 is properly wired, since it does seem to work when only controlling one single digit at a time. I am pretty sure now that the chip is broken, I will simply test it with a new one.

777-Pilot:
I am pretty sure now that the chip is broken,

I have just used your code in a UNO connected to a 7219 controlled device the same as your referenced in your OP and it exhibits the same flaw you describe. By using my own test sketch I know my UNO and 7219 display are working so your software is faulty.

Edit : After some fault finding I'm not convinced the LedControl library is working correctly.

On my UNO the randomness disappears if I user pins 7, 6 and 5 instead of 10, 9 and 8 !