Issues with Max7219 and 7 segment displays

Hello all, first time arduino user here, so forgive any of my ignorance :slight_smile: I think this is the right category, but if not I apologize!

I've been trying to use an Uno with a MAX7219 to drive a dual-digit 7 segment display. I followed this video closely to and tried to replicate it (just with 1 button and 1 dual-digit display for now)

The 7 segment display I have is actually from the same amazon link as the video creator used, however they have changed to a slightly different part number (CL3621AH, NOT the 5621BH) which has a slightly different pinout for the segment pins. I used the code from his video and everything mostly works, the numbers start at 00 and pushing the button increases the number by 1 each time. But there is some strange behavior happening. Occasionally the display just goes completely blank, all segment turn off. This happens randomly. Sometimes when I push the button the first time, sometimes I can push it a dozen times or more, but eventually the display always goes off. I have tried a different 7219 chip thinking it may be a faulty chip, but the exact same behavior occurs. I can hit the reset button on the arduino and it will reset to 00, i start pushing the button and eventually it goes off again. I have confirmed via serial monitor that the code is still working correctly (displaying the value in the serial monitor, which keeps increasing with each button press) I decided to measure the voltage from the common cathode to the segment pins. While working, it shows -3.3v, but as soon as it turns off, it shows around -5v. I have tested the display manually using 5v (with a 10k resistor) and confirmed all segments light up properly using 5v. Im far from an expert so Im not sure why the reading is - from the 7219, but I assume thats intended. But I am confused why it measures -3.3 and works, but doesnt work with -5. Perhaps there's a very simple reason for all this that I am simply too inexperienced to understand.

This is the code im using, copied directly from the author of the video linked previously

#include "LedControl.h"  // Library used for communcation with 7 segment

LedControl lc=LedControl(12,11,10,1);  //  (DIN, CLK, LOAD, number of Max7219 chips)

// Variable to hold current scores
int displayone=0;
int displaytwo=0;

// Variables to split whole number into single digits
int rightdigit;
int leftdigit;

// Switches pin connection to Arduino UNO
#define switchone 2
#define switchtwo 3


void setup() {
  pinMode(switchone,INPUT_PULLUP);
  pinMode(switchtwo,INPUT_PULLUP);
  
  lc.shutdown(0,false);  // Wake up MAX7219

  lc.setIntensity(0,7);  // Set brightness to medium

  lc.clearDisplay(0);  // Clear all displays connected to MAX7219 chip #

// Put zeros on both displays at startup
  
  lc.setDigit(0,0,0,false);  // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0,1,0,false);
  
  lc.setDigit(0,2,0,false);
  lc.setDigit(0,3,0,false);

}


void loop() { 

  // If switch 1 is clicked
  if (!digitalRead(switchone)) {
    
    displayone++;  // Increase score by 1
  
    // convert whole number to single digits
    rightdigit=displayone%10;
    leftdigit=displayone%100/10;

    // Display extracted digits on the display
    lc.setDigit(0,0,leftdigit,false);
    lc.setDigit(0,1,rightdigit,false);

    
    // Wait until switch is released to continue
    while (!digitalRead(switchone)) { 
    }
    delay(5);  // Small delay to debounce the switch
  }

    if (!digitalRead(switchtwo)) {
      
    displaytwo++;
  
    rightdigit=displaytwo%10;
    leftdigit=displaytwo%100/10;

    lc.setDigit(0,2,leftdigit,false);
    lc.setDigit(0,3,rightdigit,false);

    while (!digitalRead(switchtwo)) { 
    }    
    delay(5);
  }
}

The one thing I didnt include in my circuit is the capacitors. I asked a friend whos much better with this stuff and he said he didnt think that would cause this issue, but I realize that could be incorrect. I dont have any loose caps hanging around to throw into the circuit currently, so Ive tried without one. I will check my dead electronics pile so see if I can find the correct caps and pull them from another board. If my issue is purely the lack of caps, Im going to feel like a bigger nub than I already to :grimacing:
I also used a pull-down resistor (10k) from the 2 GND pins on the 7219, because the display wont light up at all without that, which is strange because none of the other circuits ive seen using a 7219 use a pull down in this way. Other than that, my wiring is exactly the same as in the linked video, just with 1 dual-digit display and 1 button instead of 2. I would make my own diagram but tinkercad tool doesnt seem to have the 7219 in its library and I wasnt sure what other tools existed for this purpose, any suggests what I should use would be appreciated, and I will follow up with a proper diagram.

Also wanted to note that I also tried the example code from the LedControl library and the same exact thing occurs where the display goes blank randomly. It seems to only happen if you change the digits. With the code shown in the original post, I can leave it on 00 and not press the button and it doesnt ever turn on. It's only randomly turning off when changing digits.
Additionally, I notice the onboard LED will sometimes come on while changing digits, even though theres nothing addressing that LED. it will sort of "fade" in, reach full brightness, then it suddenly goes off, usually at the same time the 7 segment does. Other times it will slowly come on, then fade out, getting so dim that you can see the tiniest but of light coming from it. Could this indicate an issue with the arduino?

Cheers

Two very different parts. One is common anode and one is common cathode.
The MAX7219 can only drive common cathode.

Russian Roulette.

? Didn't you ground them to the Arduino?
Show us a picture of the build.
Leo..

I was assuming that the person in the video used the 5621BH due to his Project Page Guide, which shows a 7 seg with 5621BH printed on the side, though his link to buy them is to a CC unit, not a CA. I guess he just happened to use a pic of a CA display for his guide. Just to confirm though, I DO have the CL3621AH - which are CC so no issues there.

Both GND pins from the 7219 are in fact connected to the ground rail on the breadboard, which is of course connected to one of the GND pins on the arduino. But without a resistor, the display flickers briefly, and does nothing. I randomly decided to try a different resistor, 30ohm instead of the 10k i was using before, and it actually works! The display stays on perfectly now!

Im not sure a pic of this mess of jumper wires will help much, hard to see where anything goes with all these wires. I downloaded fritzing and im making a proper diagram now..

I have the two GND pins jumpered together into a different row, then that row has a 30ohm resistor to the GND rail. Everything is working in this configuration, though I dont understand why. No other 7219 circuits ive seen specify a pull down off the GND pins. :person_shrugging:

Heres the diagram. I think ive done it correctly

Don't trust Dupond wires. Don't trust a breadboard.
Resistors in the ground lines are not the answer.
Use two ground wires to the Arduino to test.

What value is the Rset resistor (pin18).
Leo..

its a 3.3k. Ive also had a 10k in there and it is the same. The only way I can make it work is by adding the resistor to the ground. I even connected the 2 GND pins directly to the 2 other GND pins on the arduino and got the same non functioning behavior. side note - isnt it Iset? i thought thats what the datasheet labeled it as. Or is that the same thing? I dont actually know what the i/r stands for..

Can you elaborate on why I shouldnt trust the wires or breadboard? What don't I know? does the length of those wires open your circuit up to emi or something? Shorter connections reduce random issues and such?

thanks for the help!

Iset is the current that the chip sends through the LED display.
The datasheet recommends values between 10k and 50k.

Broken wires and bad quality breadboards are not uncommon.
But I don't think that's your problem. Did you already add that (100n ceramic) capacitor across the power/GND pins of the MAX7219.

Your friend is totally 100% wrong about this.

See my tutorial on the matter.

I have also looked at the project guide you are trying to follow and it is a bit rubbish. There are NO power supply decoupling capacitors on it. Only capacitors acting as debounce protection for the switches. So you need to add your own.

Not yet, I could not find one so I will have to purchase one and follow up!

I will give it a read, probably tomorrow though as its nearly midnight and I probably wouldnt absorb any of it.

Little note though, Ive seen several guides and videos for 7 segment circuits using this setup and so far they have all shown those 2 same caps, nothing else. Once I read your tutorial tomorrow Ill attempt to add caps to correct this, though I may have follow up questions depending on how much of the material doesn't make sense to me :stuck_out_tongue:

Thanks for the help!