MAX7219 and Common Anode displays with LedControl

spencer2004:
ok I have got it working perfectly

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

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

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

LedControl.zip (5.29 KB)

LordPants:
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 ..

http://www.instructables.com/files/orig/F79/UC7X/HKCJMPGV/F79UC7XHKCJMPGV.zip

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

Cheers
Jay

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.

Mike

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:

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

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

How I can apply the patch?
What I do with this file .patch?

LordPants:
I'm working on a project that uses lots of 7-segment LED displays, and I'm using the MAX7219 IC for its wonderful multiplexing and constant current features. Since the displays I found were common anode (not the common cathode the MAX7219 datasheet specifies), I had to modify the LedControl library a bit to accommodate them. I will share my methods and code here to get feedback before I upload any updated libraries.

The 7219 can be easily used with common anode displays, as long as things are wired up "backwards." In other words, since the pins for DIG-0 through DIG-7 are current sinks and the pins for SEG-DP through SEG-G are current sources, they can be swapped to provide appropriate power to a common anode display. Wiring should be:

Wiring for Common anode display

MAX7219 | Display
DIG-0  | SEG-DP
DIG-1  | SEG-A
DIG-2  | SEG-B
...    | ...
DIG-7  | SEG-G
SEG-DP  | Anode of Digit 0
SEG-A  | Anode of Digit 1
...    | ...
SEG-G  | Anode of Digit 7




Now since the 7219 scans digit-by-digit, and we've swapped digits with segments, it's now going to scan segment-by-segment on the common anode displays, unless we modify the data we're sending to it. The data for the entire display is represented by an 8-byte array, with each byte corresponding to one digit and each bit corresponding to one segment. To get it to work to our wiring scheme, we have to flip it: we transpose the bit matrix.

Here are the two matrices for displaying "01234567" with no decimal points on an 8-digit display (in NO DECODE mode, which LedControl uses). Each row of the matrix is stored as a byte in an array (in LedControl, it's in the status[] array).


Common cathode (standard)  Common anode (transposed)
    DP A B C D E F G            DP A B C D E F G
    +----------------          +----------------
  0 | 0 1 1 1 1 1 1 0        0 | 0 0 0 0 0 0 0 0
  1 | 0 0 1 1 0 0 0 0        1 | 1 0 1 1 0 1 1 1
  2 | 0 1 1 0 1 1 0 1        2 | 1 1 1 1 1 0 0 1
  3 | 0 1 1 1 1 0 0 1        3 | 1 1 0 1 1 1 1 1
  4 | 0 0 1 1 0 0 1 1        4 | 1 0 1 1 0 1 1 0
  5 | 0 1 0 1 1 0 1 1        5 | 1 0 1 0 0 0 1 0
  6 | 0 1 0 1 1 1 1 1        6 | 1 0 0 0 1 1 1 0
  7 | 0 1 1 1 0 0 0 0        7 | 0 0 1 1 1 1 1 0




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.


#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1,true); // lc is our object
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
// true since this is a common anode display setup
void setup() {
  lc.shutdown(0,false); // turn off power saving, enables display
  lc.setIntensity(0,5); // sets brightness (0~15 possible values)
  lc.clearDisplay(0); // clear screen
}
void loop() {
  // display 0-7, cascading on the 8 displays
  for(int i=0; i<8; i++) {
    lc.setDigit(0,i,i,false);
    delay(250);
    lc.clearDisplay(0);
  }
}




Comments, questions, and critiques are welcome.

LordPants:
I'm working on a project that uses lots of 7-segment LED displays, and I'm using the MAX7219 IC for its wonderful multiplexing and constant current features. Since the displays I found were common anode (not the common cathode the MAX7219 datasheet specifies), I had to modify the LedControl library a bit to accommodate them. I will share my methods and code here to get feedback before I upload any updated libraries.

The 7219 can be easily used with common anode displays, as long as things are wired up "backwards." In other words, since the pins for DIG-0 through DIG-7 are current sinks and the pins for SEG-DP through SEG-G are current sources, they can be swapped to provide appropriate power to a common anode display. Wiring should be:

Wiring for Common anode display

MAX7219 | Display
DIG-0  | SEG-DP
DIG-1  | SEG-A
DIG-2  | SEG-B
...    | ...
DIG-7  | SEG-G
SEG-DP  | Anode of Digit 0
SEG-A  | Anode of Digit 1
...    | ...
SEG-G  | Anode of Digit 7




Now since the 7219 scans digit-by-digit, and we've swapped digits with segments, it's now going to scan segment-by-segment on the common anode displays, unless we modify the data we're sending to it. The data for the entire display is represented by an 8-byte array, with each byte corresponding to one digit and each bit corresponding to one segment. To get it to work to our wiring scheme, we have to flip it: we transpose the bit matrix.

Here are the two matrices for displaying "01234567" with no decimal points on an 8-digit display (in NO DECODE mode, which LedControl uses). Each row of the matrix is stored as a byte in an array (in LedControl, it's in the status[] array).


Common cathode (standard)  Common anode (transposed)
    DP A B C D E F G            DP A B C D E F G
    +----------------          +----------------
  0 | 0 1 1 1 1 1 1 0        0 | 0 0 0 0 0 0 0 0
  1 | 0 0 1 1 0 0 0 0        1 | 1 0 1 1 0 1 1 1
  2 | 0 1 1 0 1 1 0 1        2 | 1 1 1 1 1 0 0 1
  3 | 0 1 1 1 1 0 0 1        3 | 1 1 0 1 1 1 1 1
  4 | 0 0 1 1 0 0 1 1        4 | 1 0 1 1 0 1 1 0
  5 | 0 1 0 1 1 0 1 1        5 | 1 0 1 0 0 0 1 0
  6 | 0 1 0 1 1 1 1 1        6 | 1 0 0 0 1 1 1 0
  7 | 0 1 1 1 0 0 0 0        7 | 0 0 1 1 1 1 1 0




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.


#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1,true); // lc is our object
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
// true since this is a common anode display setup
void setup() {
  lc.shutdown(0,false); // turn off power saving, enables display
  lc.setIntensity(0,5); // sets brightness (0~15 possible values)
  lc.clearDisplay(0); // clear screen
}
void loop() {
  // display 0-7, cascading on the 8 displays
  for(int i=0; i<8; i++) {
    lc.setDigit(0,i,i,false);
    delay(250);
    lc.clearDisplay(0);
  }
}




Comments, questions, and critiques are welcome.

Boris94:
How I can apply the patch?
What I do with this file .patch?

hello Boris,
at the end i managed to make this library work from Lord Of The Pants, what you have to do is take the patch file, name it as follow "common-anode.patch" then put it in LedControl folder, then go to LedControl.h open it with notepad or else and put this line or make sure it's there at the top of the file after the comments "#include <common-anode.patch>"
copy the other files of course and rewrite the original files
and you are good to go

Cheers

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

Still i am unable to drive common anode display using your patched library and sample code ! common cathode working well as usual.
Help pls

Thanks guys for your good work.

I sorted out the problem, it was my mistake, Max7219 pin connection must be changed to use common anode display.

I have the anode patch working on my 5digit 7 segment displays, but the processing time is slow. I assume it is slow due to the transpose functions.

Is there a way to change the byte charTable instead of the transpose computations? I have been trying this over the weekend and not come up with a working product. I only need the ledcontrol to do anode and numbers only.

I have tried to change the byte charTable using this:

Common cathode (standard)   Common anode (transposed)
     DP A B C D E F G            DP A B C D E F G
    +----------------           +----------------
  0 | 0 1 1 1 1 1 1 0         0 | 0 0 0 0 0 0 0 0
  1 | 0 0 1 1 0 0 0 0         1 | 1 0 1 1 0 1 1 1
  2 | 0 1 1 0 1 1 0 1         2 | 1 1 1 1 1 0 0 1
  3 | 0 1 1 1 1 0 0 1         3 | 1 1 0 1 1 1 1 1
  4 | 0 0 1 1 0 0 1 1         4 | 1 0 1 1 0 1 1 0
  5 | 0 1 0 1 1 0 1 1         5 | 1 0 1 0 0 0 1 0
  6 | 0 1 0 1 1 1 1 1         6 | 1 0 0 0 1 1 1 0
  7 | 0 1 1 1 0 0 0 0         7 | 0 0 1 1 1 1 1 0

What am i missing?

It is probably too late for you if you have your 8x8s soldered in place.

I found that all I had to do was rotate the displays 90 degrees counterclockwise so that the pins are on the left and right instead of top and bottom. You also need to rewire the pins.

MAX7219 pin 22 <-----> matrix pin  9
MAX7219 pin 14 <-----> matrix pin 14
MAX7219 pin 16 <-----> matrix pin  8
MAX7219 pin 20 <-----> matrix pin 12
MAX7219 pin 23 <-----> matrix pin  1
MAX7219 pin 21 <-----> matrix pin  7
MAX7219 pin 15 <-----> matrix pin  2
MAX7219 pin 17 <-----> matrix pin  5
MAX7219 pin  2 <-----> matrix pin 16
MAX7219 pin 11 <-----> matrix pin 15
MAX7219 pin  6 <-----> matrix pin 11
MAX7219 pin  7 <-----> matrix pin  6
MAX7219 pin  3 <-----> matrix pin 10
MAX7219 pin 10 <-----> matrix pin  4
MAX7219 pin  5 <-----> matrix pin  3
MAX7219 pin  8 <-----> matrix pin 13

Thanks IEEE, I have everything soldered and already have some proto boards, so I need to change it with a software solution.

Would this work with 4x 4-digit 32pin kingbright CA56-11EWA modules, and 2 max7221 divers?

This is the schematic i came up with, just wanting to see if anyone can double-check it and let me know if they see any issues with it.

Attached are the PDF for the display module, as well as a photo export from eagle.

CA56-11EWA.pdf (239 KB)

ArcAiN6, I haven't tried the way that ieee488 says to try a couple posts up. If you do it that way, I think you would use the standard LedControl. If you do it the other way shown at the beginning of this thread, you will need to use the LedControl modified for anode.
Looking at your wiring schematic, it is not wired as per the anode version at the beginning of the thread.
Let me know if you get it working with the 90 degree counterclockwise wiring. I would really like to know how it works.
Thanks and good luck!

hrm... you know.. Thanks for catching that, not sure how i managed to weird that out like that lol.. Glad i didn't solder yet :smiley:

Here Something else some of you may find interesting:

Hi Lordpants
I ussualy use ledcontrol lib for control common cathode, but i found you make the patch, sorry question is how to use the patch with the library ? is there any Anode display library for max7219 ?
Thank you in advance

Greetings ,

Can someone guide me on how to update led control library ? I am also trying my hand on interfacing common anode 7 segment display with max7219 ...

Years late, but found this thread while struggling with 8 x 8 LED matrices and MAX7221.
This subject has to be one of the most confusing. References to common anodes/cathodes, column anodes/cathodes. Common anode/cathode makes no sense with discrete LED matrices. Common row anode/cathode makes sense. Common cathode on 7-segment displays makes sense as well.
I tried a commercial (Kingbright TC15-11CGKWA ) 8 x 8 "common cathode" matrix (rows are anodes, columns are cathodes). Carefully wired it up to match the MD_MAX72xx Parola hardware scheme (columns as cathodes). Fired it up and it worked fine, but 90-degrees away from the result expected from the datasheet. MD uses a "common anode" 1088B that looks like a common column anode arrangement that might be part of the problem.
I still don't understand why it was wrong, so will be unsoldering and starting again, but for what it's worth, the Kingbright display has the part number printed on one side that looks like the bottom of the display if it was stood up vertically. Wrong -the part number needs to be on the left and Kingbright pin 1 is top left looking at the display side, pins behind.
I'm not going to try and understand why it was wrong to start with, turning it 90-degrees is a lot easier.
The MD_MAX72xx Hardware Mapper sketch helped a lot

I know this is an old thread but it's the closest match I've found for what I would like to build.
Just looking for some info to see if my idea will even fly.
I would like to build a 5 digit 7 segment display using 3mm leds. 11 leds in each segment. From what I've read, the current will be WAY too high for the MAX7219 even if I use a seperate MAX7219 for each digit.
Are their other options for me or should I see about trimming down some of the leds?