Wiring Forum
Wiring Hardware >> Tangible computing >> The Big RGB Leds matrix tests post.

Message started by julienb on 05/28/08 at 12:26:19

Title: The Big RGB Leds matrix tests post.
Post by julienb on 05/28/08 at 12:26:19

I post this new thread in order to clarify some questions.
The main problem in driving a RGB Led matrix isn't the hardware, but the code for a lot of us.
I mean: Arduino or Wiring, or ... no problem with them.. But the code you run is the problematic point.

I did some basics tests with a particular rigour in building, verifying, evaluating.

Only 4x3 rgb led matrix for the moment (the final target: 8x8)
Common Cathode RGB Leds like that:

Each DIG legs of the maxs  to the lines
Each SEG legs of the first maxs to one color on a column and the same for the second

I decided to test 3 libraries: LedControl, Matrix() and a code for max72xx (I named this last one like that further.. but it is "only" a piece of code useable with the max72xx).

These 3 lib/code weren't tested with 3 different hardware configuration: only one Max7221 to drive only one color, 2 Max7221 cascaded, 2 Max7221 each one directly link to the Wiring Board (thus 6 pins involved)

1/ Only one max/1 color driven
LedControl works fine.
Matrix() works fine.
Code for max72xx works fine.

2/ 2 Max7221  each one directly link to the Wiring Board
LedControl doesn't work !
Matrix() works fine doesn't work ! (strange but it doesn't work! probably the same problem as further)
Code for max72xx works fine => the code isn't make for that.

3/ 2 Max7221 cascaded
LedControl and Matrix() and Code for max72xx doesn't work fine.
Same problem:
when I power on a single color of a particular led, this particular led is ok BUT on the same column, all the others leds blink with the color driven on the right first led.
I guess it is THE DIG's sharing problem.
Line 1 : DIG1 for the first MAX and DIG2 for the second MAX
-               -                       -             -                -            -
Line n : DIGn for the first MAX and DIG2 for the second MAX

I made a very basic test: I shutdown the second max when I want to power on the color driven by the first max. It is a crappy code but .. it works: no blinking strange effects on the columns etc.

a lot of posts on the arduino forums seem to describe this problem.
It is caused by the lines sharing between the maxs.
one way seems to be : Multiplexing MAX72xx

It involves an Interrupt Sub Routine that acts each time a modification is made on the matrix.
There is a cyclically power on and down explains here: http://www.maxim-ic.com/appnotes.cfm/appnote_number/1004 and Multiplexing MAX72xx.

But this code doesn't work with Wiring Board!

There is a library problem.
In the mstimer2, it is written: "works only with Atmel168"
Wiring is an Atmel128 based board.

Indeed, it could be easy to trick and cheat with this code. I'm unable to do that :-(

Does someone could? Did someone do that ?
if someone could hack the mstimer2 : I'm sure it could be a useful playground on this site, cause i'm not the only one who want to do that.

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 05/30/08 at 08:43:18
as I'm not able to create a mstimer2-alteration that can work on Wiring Board, I made a code that cause the 2 max cascaded to work only one at a time:

int sizeX = 3;
int sizeY = 2;

int bitTable[8]={ 128, 64, 32, 16, 8, 4, 2, 1 };

int dataIn = 5;
int load = 6;
int clock = 7;

int maxInUse = 3;    //change this variable to set how many MAX7219's you'll use

int e = 0;           // just a varialble

                    // define max7219 registers
byte max7219_reg_noop        = 0x00;
byte max7219_reg_digit0      = 0x01;
byte max7219_reg_digit1      = 0x02;
byte max7219_reg_digit2      = 0x03;
byte max7219_reg_digit3      = 0x04;
byte max7219_reg_digit4      = 0x05;
byte max7219_reg_digit5      = 0x06;
byte max7219_reg_digit6      = 0x07;
byte max7219_reg_digit7      = 0x08;
byte max7219_reg_decodeMode  = 0x09;
byte max7219_reg_intensity   = 0x0a;
byte max7219_reg_scanLimit   = 0x0b;
byte max7219_reg_shutdown    = 0x0c;
byte max7219_reg_displayTest = 0x0f;

void putByte(byte data) {
 byte i = 8;
 byte mask;
 while(i > 0) {
   mask = 0x01 << (i - 1);      // get bitmask
   digitalWrite( clock, LOW);   // tick
   if (data & mask){            // choose bit
     digitalWrite(dataIn, HIGH);// send 1
     digitalWrite(dataIn, LOW); // send 0
   digitalWrite(clock, HIGH);   // tock
   --i;                         // move to lesser bit

void maxSingle( byte reg, byte col) {  
//maxSingle is the "easy"  function to use for a     //single max7219

 digitalWrite(load, LOW);       // begin    
 putByte(reg);                  // specify register
 putByte(col);//((data & 0x01) * 256) + data >> 1); // put data  
 digitalWrite(load, LOW);       // and load da shit

void maxAll (byte reg, byte col) {    // initialize  all  MAX7219's in the system
 int c = 0;
 digitalWrite(load, LOW);  // begin    
 for ( c =1; c<= maxInUse; c++) {
 putByte(reg);  // specify register
 putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
 digitalWrite(load, LOW);

void maxOne(byte maxNr, byte reg, byte col) {  
//maxOne is for adressing different MAX7219's,
//whilele having a couple of them cascaded

 int c = 0;
 digitalWrite(load, LOW);  // begin    

 for ( c = maxInUse; c > maxNr; c--) {
   putByte(0);    // means no operation
   putByte(0);    // means no operation

 putByte(reg);  // specify register
 putByte(col);//((data & 0x01) * 256) + data >> 1); // put data

 for ( c =maxNr-1; c >= 1; c--) {
   putByte(0);    // means no operation
   putByte(0);    // means no operation

 digitalWrite(load, LOW); // and load da shit

void setup () {
 pinMode(dataIn, OUTPUT);
 pinMode(clock,  OUTPUT);
 pinMode(load,   OUTPUT);

//initiation of the max 7219
 maxAll(max7219_reg_scanLimit, 0x07);    
 maxAll(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
 maxAll(max7219_reg_shutdown, 0x00);    // not in shutdown mode
 maxAll(max7219_reg_displayTest, 0x00); // no display test
  for (e=1; e<=8; e++) {    // empty registers, turn all LEDs off
 maxAll(max7219_reg_intensity, 0x0f & 0x0f);    // the first 0x0f is the value you can set
                                               // range: 0x00 to 0x0f

void loop () {




void ShutdownR()
 maxOne(1,max7219_reg_displayTest, 0x00);
 maxOne(1,max7219_reg_shutdown, 0x00);

void ShutdownB()
 maxOne(2,max7219_reg_displayTest, 0x00);
 maxOne(2,max7219_reg_shutdown, 0x00);

void WakeUpR()
 maxOne(1,max7219_reg_displayTest, 0x00);
 maxOne(1,max7219_reg_shutdown, 0x01);

void WakeUpB()
 maxOne(2,max7219_reg_displayTest, 0x00);
 maxOne(2,max7219_reg_shutdown, 0x01);

This code is an alteration of a code already existing.

That WORKS FINE for 3x2 leds matrix and for 2 colors only!
I just hope it could work for :
- 8x8 leds
- 3 colors with one max more

I tested the same things for 3x2 with one max more cascaded (total = 3 max)
it only works for 2 colors !
I guess it is an interruption problem (I mean, ISR would fix it!)
But I'm not a specialist...
But for 2 colors, great it works!!

the principle will be:

update_the_matrix(); // in order to update the state of leds : blinking, off, on, colors
shutdown_max1() ; wakeup_max2();
shutdown_max2() ; wakeup_max3();
shutdown_max3() ; wakeup_max1();

Title: Re: The Big RGB Leds matrix tests post.
Post by N201LJ on 06/04/08 at 11:42:20
You know, I was thinking about your posts about using MAX7221 to drive a large LED matrix....

The MAX7221 is great for driving 7-segment LED's, but there may be a simpler way to do this.  What about using a MCP23S17 and an MCP23S08 to drive the matrix as depicted?  These are 16 bit and 8 bit SPI interface port expanders.  The MCP23S17 could drive the columns and the MCP23S08 could drive the rows (via a ULN2803 low side driver, perhaps; since you have a common cathode arrangement).  

You would have to write your own code; but it should be fairly easy.

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/04/08 at 12:14:58
N201LJ, you raise another idea with your post.
it reminds me a guy wrote about i/o pins of the board.
the wiring board have A LOT of I/O Digital pin:
would it be possible to use them directly to control columns and rows?

another idea: another schematic has been drawn in another post on SparkFun forum: http://forum.sparkfun.com/viewtopic.php?t=10617
But the schematics is for common anode leds (but the concept could be the same..)

Title: Re: The Big RGB Leds matrix tests post.
Post by N201LJ on 06/04/08 at 20:16:08
Sure - you could drive the columns directly with 16 digitals pins on the Wiring board, and the 8 row pins via a transistor array e.g. ULN2803.  It would consume a lot of pins, though.


Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/04/08 at 20:43:42
I watched the ULN2803 datasheet.

columns: 8 RGB Leds = 8 x 3anodes = 24 pins (?)
rows: 8 RGB leds = 8 cathodes = 8 pins?

It could be nice to create a library to manage that.
I mean: to have a more friendly  code.

But the hardware first.
N201LJ, could you help me to draw a schematic?

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/05/08 at 18:34:35
I found that:

excepted the fact that there isn't MAX7221 (but 74HC595) and no Wiring board... Does the principle with the transistor array is the one you talked about ?

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/06/08 at 20:15:26
it seems the transistors solution is THE solution for me.

A web-friend made that schematic:
1 max + 24 transistors + 3 Digital Out pins for driving the max + 3 Digital Out pins for driving the 24 transistors

do you think performances could be fine?

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/10/08 at 17:49:48
my last idea: only transistors!

I only did 4x4, but the target is 8x8:

as the wiring board owns MANY digital pins, it could be nice to only use transistor.
I guess it could work..

any suggestions, ideas, advices ?

3 pins per column one for each color = 8 columns x 3pins = 24 pins
1 pin per row = 8 rows x 1 = 8 pins
TOTAL= 32 pins used.
indeed it is very much.

in this case, no cycling except if I want to reduce the power needed... Am I wrong?

Title: Re: The Big RGB Leds matrix tests post.
Post by julienb on 06/10/08 at 20:41:49
i didn't precise that there should be a cycle too.
if I understand well, I'll have to cycle one led at a time on each line... because of the common cathode..
I mean, if I want to do that:

O = Off
X = On

without cycling it would be impossible: on the second row transistor for ground commuted + the same in the third.
so if in the second row / second column I want to power up, in all the columns with ground commuted on the row all leds will be on.

so, May I have to cycle the row? the columns?

I don't know the running frequency of my board (wiring)
I mean, my loop could be fast but others treatment will have to be done (buttons, communications)

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.