Go Down

Topic: MAX7219 and Common Anode displays with LedControl (Read 8421 times) previous topic - next topic


Yes, the Arduino can supply current for 2 matrixes. I have powered four, with 9V source. 12V was too much, the regulator would over heat and shutdown.

Theoretically, to have two MAX7219 driving a dual color common cathode matrix one would wire it like this, and multiplex the outputs by alternately putting each part in shutdown mode:

"When the MAX7219 is in shutdown mode, the scan oscillator is halted, all segment current sources are pulled to ground, and all digit drivers are pulled to V+, thereby blanking the display."

The diodes isolate each part from the common cathode so the MAX7219s do not interfere with each other when sinking cathode current.

As a hardware engineer, I would use SPI.transfer()s to communicate to each part, with a seperate ssPin to each part so that you could update one or the other.
SCK - to MAX7219 CLK pin 13
MOSI - MAX7219 DIN pin 1
ssPin - to MAX7219 LOAD pin 12

Or, daisy chain them and write a loop that updated the 8 registers on each one every so many mS for animations.
I don't follow this fascinintion with using the equivalent of shiftout() for sending data to the parts:

Arduino pin 12 is connected to MAX7219 DIN pin 1
Arduino pin 11 is connected to MAX7219 CLK pin 13
Arduino pin 10 is connected to MAX7219 LOAD pin 12
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Hi d82k,

If I'd wire your matrix I'd make it like this (I changed the SEG connections only):
This way I think the multiplex would be better handled by the driver (and the LedControl library, I think).
Lines would be lines and cols=cols... easier to address them individually.

Code: [Select]

Col Pin _______ Pin Row
DIN    1|o |24 DOUT
1 23 DIG 0  2| |23 SEG D 13   4
5 2 DIG 4  3|   M |22 SEG DP 12   8
GND    4|   A |21 SEG E 3   5
7 8 DIG 6  5|   X |20 SEG C 16   3
3 17 DIG 2  6|   7 |19 V+
4 14 DIG 3  7|   2 |18 ISET
8 11 DIG 7  8|   1 |17 SEG G 9   7
GND    9|   9 |16 SEG B 19   2
6 5 DIG 5 10| |15 SEG F 6   6
2 20 DIG 1 11|  RED |14 SEG A 22   1
LOAD  12|_______|13 CLK

I'm also using a 22kOhm resistor... I think the leds will just light up a bit brighter... but I guess the extra current wont harm them, as per the info in the datasheet.

I'm a also a novice so... I'm still figuring it out too but from what I've read the capacitors' function is to smooth the current drops and stabilise it since the MAX7219 seems to be quite sensible.

Other heads up when connecting more than one matrix is to loop through all of then in the setup function:

Code: [Select]

void setup() {
  for(int index=0;index<lc.getDeviceCount();index++) {

Rhawbert Costa


Hi, sorry for my ignorence but how do I patch the origional ledControl libary with the common-anode patch? I tried to find out how to do it on Google but I couldn't find anything.


Are you driving a matrix, or 7-segment displays?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


I need to drive an 8 digit common anode 7 seg display.

I have sort of figured out how to patch it but I can't get it to work; I patched the source file with GnuWin32 and it almost works but it says that hunk #4 failed at 219 whereas hunk 1, 2, 3 and 5 are successful. It says that I should use the -p or --strip option but I don't know how they work.

Would it be possible for somebody to upload the patched source file? It would be of great help.


Never mind I finally got it to work. It literally took me the whole day to figure it out!


May 03, 2013, 08:42 pm Last Edit: May 03, 2013, 08:51 pm by spencer2004 Reason: 1
ok I have got it working perfectly but I am having some confusion with the value for the ISET resistor; I origionally used a 28k ohm resistor which is what the data sheet recommends but the 7 segment display was fairly dim so I tested it with a multimeter and each segment was drawing only 2 mA so I played around with the resistance value and I finally got each segment to run at 10 mA with a value of 2.2k which is much lower than it should be. Is it possible that using the MAX7219 as a common anode display driver drasticaly changes the value required for the ISET resistor?

I made sure that the software brightness control was at the maximum value of 15 and I have no resistors between the IC and the 7 segment display by the way.

Edit: Each segment draws 10mA only when 1 digit is activated, they progressively draw less current and get dimmer as more digits are activated until they only draw 4.25mA with all 8 digits activated, strangely the current draw per segment is unaffected if other segments on the same digit are activated (e.g. displaying a number 1 draws 20mA, a number 8 draws 70mA).


ok I have got it working perfectly

can you help me how to applicate de patch without hunk error?
i work under mac with unix
thank you


can you help me how to applicate de patch without hunk error?
i work under mac with unix
thank you

I forgot how I did it but here are the patched files. Just extract it in to your LedControl folder.


My patch for LedControl is attached. It's completely backwards compatible with existing code. To use it with common anode displays, you only have to add a boolean option to the object creation. The transposition is handled completely by the library.

Comments, questions, and critiques are welcome.
Hi I am using the MakerSpace version of the LEDControl Library ..


It has a few extra methods which allow easy character and string display on matrix led's .. but the core code is essentially the same as LEDControl ... at least i believe it is ...

Will this patch work with this version LEDControl ?, if so how do you apply it ?

I'm using it to drive Common Anode 8x8 matrix

My code is working fine but cols & rows are reversed .... so this patch should solve the issue ... i think



I am currently rewriting and significantly expanding LedControlMS.  I only have 8 8x8 single-color LEDs matrices right now.  8 more coming and I have an external 5v supply so running them will not be a problem.

With the time I have, it will be a couple of weeks.  Won't have that reverse polarity patch put in unless I can find hardware to try it out with.

This is not as elaborate as MD_Parola (yet or maybe ever) but I find I cannot get very far reading that code.  Mine is much more transparent and easy to modify.  In the spirit of LedControl libraries.

Full width coarse and smooth scrolling is working with variable rate from WAY too fast to read to as slow as you want it.  Also up and down scrolling either by individual matrix or in order scrolling or or down in unison or by arbitrary step size and also speed variable. 

I want to tame the crawling (horizontal movement) and let the user easily control it and put in things like flying individual characters in and out (left and right) at user selectable speed, justification and other stuff.  So it will do more scroll and crawl functions soon.  And you can easily add your own 8x8 characters.  There is room for another 125 or so.  Already has all ASCII upper/lower and special characters plus degree symbol, US Cent sign and 3 grids.

Will post somewhere when I am ready to upload it somewhere.  Probably my web site.  The extreme speed is limited to AVR chips right now (Uno and many others) on arbitrary pins 8-13.  Will also investigate hardware SPI this week.  Having fun and writing code...  Anyone know about "creeping featurism".  That's what's happening here!  Can be a good thing...  sometimes...

One little strangeness on capacitors.  If you use large ones, they do a good job of filtering but also add some inductance.  To take care of that, you have to add a smaller one in parallel to balance it out.  Seems wrong but you will see it a lot.



That's what the MAX7219 datasheet calls for, 0.1uF and 10uF together on the VCC pin.
To minimize power-supply ripple due to the peak digit
driver currents, connect a 10μF electrolytic and a 0.1μF
ceramic capacitor between V+ and GND as close to
the device as possible. The MAX7219/MAX7221 should
be placed in close proximity to the LED display, and
connections should be kept as short as possible to
minimize the effects of wiring inductance and electromagnetic
interference. Also, both GND pins must be
connected to ground.
10 MHz serial interface allows for Fast SPI interfacing (SPI divisor set to 2) for nearly 1byte/uS transfers. I use that when I use the chip:
Code: [Select]

PORTB = PORTB & 0b11111011; // clear SS pin, use D10 on Uno
SPI.transfer(registerAddress); // 1 to 8, can be from an array
SPI.transfer(dataToWrite); // data, can be from an array also
PORTB = PORTB | 0b00000100; // set SS pin
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Oct 05, 2015, 05:35 pm Last Edit: Oct 05, 2015, 05:36 pm by firashelou
hello LordPants,
i came across your post, i am working on common anode double digit 7 segment so i need to know please where should i put the patch you share in the beginning is it in the LedControl same library or i must create a copy and name it differently ? because my project will contain 4 Common Anode double digit 7-segment and 1 single digit CC 7-segment and 19 LEDs so it's gonna have 2 MAX7219 driving these,
the first MAX7219 will be driving the 4 double digit 7-segemt and the other MAX will do the rest
Aiming for the unreachable !

Go Up