Problem with Multiplexing the MAX72xx to Drive a 2

HI BroHogan,

I have tried to use your code on my dual LED Matrix, http://www.arduino.cc/playground/Main/MultiplexMAX72xx

However I found out that if the ISR set to be low such as 190, only green alternative col will be light up, if I set it to high such as 1000, only red alternative col will be light up. Do you have any clue?

Hi soon

I know that if the hardware is setup as in the example, and the sketch in the example is used - it will work perfectly. So let's start there!

(I even just double checked this with REL 0013. The only difference is that now you must add the mysterious #include "WProgram.h" to get the sketch to compile. >:( )

So start with that example and let me know what it looks like.

Leave the ISR set to 190 (650Hz). That setting works well for me and I am doing a lot of things in 2 colors - scrolling, sprites, Life, etc. Also, it's an 8 bit setting, so making it > 255 just rolls it over. (1000 makes it ~ 4 = 25,000Hz!)

My guess right now is that the problem is in how you have the matrix wired to the MAX chips or the matrix itself.

The matrix is a common cathode right?

The cathodes are the [u]row[/u] and are connected together for both colors right?

The anodes are the [u]column[/u] and are connected together for each color right?

The two MAX chips have there "digit" lines connected together (DIG1 to DIG1) and these are connected to the rows on the matrix - right?

If all of the above checks out, take another look at your wiring and read the Playground article again. I know from your other posts that you have had trouble with your wiring.

Hope this helps!

The only wired that connect with two MAX72XX are only the
DOUT (Red - max1) → DIN (Green-max2)
Load (red-max1) <-> load (green-max2)
clock (red-max1) <-> clock (green-max2)

The matrix is a common cathode right?
=> Yes serve for both colors
The cathodes are the row and are connected together for both colors right?
The anodes are the column and are connected together for each color right?
=> The row (cathodes) connect to both MAX1 and MAX2
=> the column of red connect to max1, and green connect to max2

The two MAX chips have there “digit” lines connected together (DIG1 to DIG1) and these are connected to the rows on the matrix - right?
=> I didn’t do that initially, but I have now wired all DIG pin to both MAX. The result is the same for both
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235865267/6#6
and
your program.

=> i use 20K resistance for each MAX chips
=> 5 V from Arduino pin to both MAX chips
=> 10m capacitor to both MAX chips

=> I didn't do that initially, but I have now wired all DIG pin to both MAX. The result is the same for both

If you didn't have DIG pins wired together and then to the rows, how did you have them wired? :-?

The example you have in the Hardware / Interfacing forum [u]will not work[/u] for an 8x8 RG Matrix. There is no ISR in that code to alternate the shutdown between the 2 MAX chips. I explained why [u]twice[/u] in that thread.

Since you now say "I have now wired all DIG pin to both MAX" can I now assume the answer to the other questions I asked you are "yes"? (You repeated the questions but without the answers.)

For example, does DIG0 on the Red MAX go to DIG0 on the Green MAX and also go to Row 0 on the matrix?

What [u]exactly[/u] does the matrix look like when the example sketch is run?

You need to throw me more "bones" so I can help you more efficiently.

If you can post a diagram of how it's wired, that should also help.

hi, If you didn't have DIG pins wired together and then to the rows, how did you have them wired? => I use the DIG pins from MAX to connect with the row of matrix directly. But didn't do wiring between the two MAX chips. => but I have also wired it now, take a look for pic 2 below.

here is the sample sketch: http://www.flickr.com/photos/siusoon/3335978173/sizes/l/ => this is basically how the matrix pin placed and my MAX chip.

http://www.flickr.com/photos/siusoon/3335978487/sizes/m/

http://www.vimeo.com/3519687 => this is the video effect, you can see specific dots light up with great intensity while on the same col other LED light up in dimmer row. I only set the program for specific LED but not the whole col.

thanks so much for your help.

hi BroHogan,

besides of the two color unstable issue, I am in parallel working with MAX/MSP to control the LED matrix display.

I would like to store several animated pattern in Arduino using EEPROM first, and then use MAX/MSP to send byte/ascii to serial Arduino and then recall those animated pattern from time to time. This seems better way instead of real time using MAX/MSP to control the Arduino with the LED and patterns.

The pattern basically I got it, but don't know how to do the write EEPROM and don't know anything need to define there. Basically I modify the example code from LEDControl to get my pattern light up. However I need to put into various function in EEPROM write at the same time, is that I need to do the 'read' part to listen to any serial communication from MAX/MSP?

soon,

I made a YouTube video of what the sample code in the playground should look like.

The video you made doesn’t appear to use this code. And since I don’t know what your code looks like, I don’t have a frame of reference (common ground) to help you sort out your problem. Can you tell me more about about how the sample code looks?

I only set the program for specific LED but not the whole col.

Sorry, I’m not sure I understand what this should mean to me.

Regarding your question about using EEPROM, I’m not too clear about that either. Yes you can store sprites in EEPROM and use LedControl to display them when you get an instruction via serial communication. If your plannung on using the EEPROM in the ATmega there are guides to help you understand how to use EEPROM.

You can store 8 bytes for each sprite. Each byte is a row (or column) Then read back each byte and use lc.setRow (or lc.setColumn) to display it. (Actually you need the use the calls with the wrappers in the example - SetRow & SetColumn because they turn off the ISR.)

But I seem to be “drinking out of a fire hose” here. :slight_smile:

I am happy to try to help you get the 8x8 RG matrix going, lets start with that. So load the sample code on your Arduino and take a movie.

here is the code:
/////////////////
//We always have to include the library
#include “LedControl.h”

#undef int
#undef abs
#undef double
#undef float
#undef round

LedControl lc=LedControl(12,11,10,2);
// red = 0, green = 1;
// pin 12 = data in, pin 11 = clock, pin 10 = load
/* we always wait a bit between updates of the display */
unsigned long delaytime=200;

void setup() {
//we have already set the number of devices when we created the LedControl
int devices=lc.getDeviceCount();
//we have to init all devices in a loop
for(int address=0;address<devices;address++) {
/The MAX72XX is in power-saving mode on startup/
lc.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,8);
ClearMatrix();
}
}

// row and col starts w/ 0. (0, row, col, true/false)

void clock_12_0() {
ClearMatrix();
lc.setLed(1,0,3,true); //freq
lc.setLed(1,0,4,true); //freq
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=1;row<3;row++) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime4);
}
delay(delaytime
10);

}

void clock_12_1() {
ClearMatrix();
lc.setLed(1,0,3,true); //freq
lc.setLed(1,0,4,true); //freq
delay(delaytime2);
lc.setLed(1,1,2,true); //freq
lc.setLed(1,1,5,true); //freq
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=1;row<3;row++) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime
4);
}
delay(delaytime*10);

}

void clock_12_2() {
ClearMatrix();
lc.setLed(1,0,3,true); //freq
lc.setLed(1,0,4,true); //freq
delay(delaytime2);
lc.setLed(1,1,2,true); //freq
lc.setLed(1,1,5,true); //freq
delay(delaytime
2);
lc.setLed(1,2,1,true); //freq
lc.setLed(1,2,6,true); //freq
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=1;row<3;row++) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime4);
}
delay(delaytime
10);

}

void clock_12_3() {
ClearMatrix();
lc.setLed(1,0,3,true); //freq
lc.setLed(1,0,4,true); //freq
delay(delaytime2);
lc.setLed(1,1,2,true); //freq
lc.setLed(1,1,5,true); //freq
delay(delaytime
2);
lc.setLed(1,2,1,true); //freq
lc.setLed(1,2,6,true); //freq
delay(delaytime2);
lc.setLed(1,3,0,true); //freq
lc.setLed(1,3,7,true); //freq
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=1;row<3;row++) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime);
lc.setLed(0,row,3,false);
lc.setLed(0,row,4,false);
}
for(int row=3;row>0;row–) {
delay(delaytime);
lc.setLed(0,row,3,true);
lc.setLed(0,row,4,true);
delay(delaytime
4);
}
delay(delaytime*10);

}
void loop() {
clock_12_0() ;
clock_12_1();
clock_12_2();
clock_12_3();
}

void ClearMatrix(){

lc.clearDisplay(0);
lc.clearDisplay(1);

}
/////////////////////////////////
I only set the program for specific LED but not the whole col.
=>from the above code, i light up individual LED instead of the whole col e.g
lc.setLed(1,0,3,true); //freq
=> 1 = greed max2, 0 = row 0, 3 = col 3
therefore this is specific to the LED but not the whole col.

thanks so much…

hi BroHogan,

Is it because I can't set the green max2 on and then immediately set the red max1 on? I cannot switch between two and need special code on that?

Is it because I . . . need special code on that?

You need special code just because you have the rows connected to 2 MAX chips. With that code you will be able to light red, green, or both (for orange).

Your sketch shows that you are not using any of the technique mentioned in the Playground. :o - There is no ISR to continuously toggle the shutdown between the 2 MAX chips. - You are making calls [u]directly[/u] to the LedControl library instead of using the "wrappers" that are described in that article.

The Playground article is both a hardware and a [u]software[/u] solution - mostly software. You are not doing anything on the software side. If you read it all the way through, hopefully, you will understand. ;)

There is also a [u]simple[/u] example at the bottom. It works, and it makes it easy to test that your hardware is set up OK.

I suggest you do the following . . . - Reread and try to understand the article. - Copy the example and load it - [u]with no changes[/u]. Run it with your hardware setup. - If it doesn't look like the video I posted, check all of your wiring an compare to the article. - Once the example works, make the required changes to your sketch. (The 2 things I mentioned above.)

Hopefully now we are on the same page. If there is something that you can't understand in the article - please let me know so that I can make it more clear for others (before I retire!)

Good luck

BTW, I modified your code to work with the technique on the Playground. (Also added the example). Video here . . . http://www.youtube.com/watch?v=5Fs3vio8314

Hi BroHogan,

I have tried to only use the sample code that you provided on SRI and didn't change any code, but still it turns out only static alternative Green row is light up :( instead of flashing red/green.

Well I think is very difficult for you to help as well, may be the hardware-wise show some difference, I may do a work around by using 1 multiplex and then light up some alternative row with red or green color. ///////////////////////////////////// Regarding the EEPROM, is that I use 'write' function to store the animation pattern with the LedControl library as well? Do you have any idea I can source the 'get an instruction via serial communication'? like a listening job from the Arduino. I wonder if I can use similar code from LedControl library (which I get used to it now and easier to understand), add the communication between serial and divided them(pattern) into various function for instructional execution.

can you explain more abit on 'store 8 bytes for each sprite'?

What I found from the Arduino playground is the site here: http://www.arduino.cc/playground/Code/EEPROMWriteAnything

Is that means that each address of EEPROM can store each set of LED pattern or that is basically refers to other things?

More I found that many website by using EEPROM requires additional hardware component, I wonder if I can just use my Arduino to do that? And I found from some tutorial that:"The microcontroller on the Arduino board has 512 bytes of EEPROM" => so I suppose 512 bytes is basically the address to locate different function?

Sorry for the long posting, as I am the new beginner in doing such kind of electronics project, but do find interest in working it out step by step.

soon,

My main goal was to help you get your matrix to work. I have modified your code and made a video to show it working. Unfortunately, I have failed to help you get it working on your hardware. (I really think you have a wiring problem.)

Now you think you have a “work around” and also have more questions about fonts in EEPROM, etc. For those questions, I suggest that you start a new thread so that you can get help from others here too.

(If I were you I would get the matrix working before trying to add these things - “step by step”)

I have included your modified code below in case that helps.

#define ISR_FREQ 190                    //190=650Hz
#define GREEN 1                         // Green MAX72xx
#define RED 0                           // Red MAX72xx
int maxInShutdown=GREEN;                // MAX7221 that is currently off 
//                       ADDED ALL THE ABOVE                                     

#include "LedControl.h"
// (NOT NEEDED IF Rel. 0013)
#undef int
#undef abs
#undef double
#undef float
#undef round

LedControl lc=LedControl(12,11,10,2); // YOUR HARDWARE
//LedControl lc=LedControl(10,9,8,2); // MY HARDWARE
// red = 0, green = 1;
// pin 12 = data in, pin 11 = clock, pin 10 = load 
/* we always wait a bit between updates of the display */
unsigned long delaytime=200;

void setup() {
  lc.setIntensity(GREEN,15);            // 0 = dim, 15 = full brightness
  lc.setIntensity(RED,12);              // red needs less brightness
  setISRtimer();                        // setup the timer
  startISR();                           // start the timer to toggle shutdown
 //                       ADDED THE ABOVE                                     
 //                       COMMENTED OUT BELOW
   //we have already set the number of devices when we created the LedControl
 //int devices=lc.getDeviceCount();
 //we have to init all devices in a loop
 //for(int address=0;address<devices;address++) {
   /*The MAX72XX is in power-saving mode on startup*/
   //lc.shutdown(address,false);
   /* Set the brightness to a medium values */
   //lc.setIntensity(address,8);
  ClearMatrix();
// }
}

// row and col starts w/ 0. (0, row, col, true/false)

void clock_12_0() {
 ClearMatrix();
 SetLed(1,0,3,true); //freq  REPLACED ALL "lc.setLed" WITH "SetLed"
 SetLed(1,0,4,true); //freq
  for(int row=3;row>0;row--) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
   for(int row=1;row<3;row++) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
 for(int row=3;row>0;row--) {  
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime*4);    
     }
  delay(delaytime*10);  

}

void clock_12_1() {
ClearMatrix();
 SetLed(1,0,3,true); //freq
 SetLed(1,0,4,true); //freq
  delay(delaytime*2);
  SetLed(1,1,2,true); //freq
  SetLed(1,1,5,true); //freq
  for(int row=3;row>0;row--) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
   for(int row=1;row<3;row++) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
 for(int row=3;row>0;row--) {  
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime*4);    
     }
  delay(delaytime*10);  


}

void clock_12_2() {
ClearMatrix();
 SetLed(1,0,3,true); //freq
 SetLed(1,0,4,true); //freq
  delay(delaytime*2);
  SetLed(1,1,2,true); //freq
  SetLed(1,1,5,true); //freq
 delay(delaytime*2);
 SetLed(1,2,1,true); //freq 
 SetLed(1,2,6,true); //freq
  for(int row=3;row>0;row--) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
   for(int row=1;row<3;row++) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
 for(int row=3;row>0;row--) {  
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime*4);    
     }
  delay(delaytime*10);  


}

void clock_12_3() {
ClearMatrix();
 SetLed(1,0,3,true); //freq
 SetLed(1,0,4,true); //freq
  delay(delaytime*2);
  SetLed(1,1,2,true); //freq
  SetLed(1,1,5,true); //freq
 delay(delaytime*2);
 SetLed(1,2,1,true); //freq
 SetLed(1,2,6,true); //freq
 delay(delaytime*2);
 SetLed(1,3,0,true); //freq
 SetLed(1,3,7,true); //freq
  for(int row=3;row>0;row--) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
   for(int row=1;row<3;row++) {
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime);
     SetLed(0,row,3,false);
     SetLed(0,row,4,false);
     }
 for(int row=3;row>0;row--) {  
     delay(delaytime);
     SetLed(0,row,3,true);
     SetLed(0,row,4,true);
     delay(delaytime*4);    
     }
  delay(delaytime*10);  


}
void loop() { 
   clock_12_0() ;
  clock_12_1();
  clock_12_2();
  clock_12_3();
}

/* REPLACED THIS FUNC
void ClearMatrix(){
 lc.clearDisplay(0);
 lc.clearDisplay(1);
}
*/
// ADDED EVERYTHING BELOW
/////////////////////////////ISR Timer Functions ///////////////////////////
ISR(TIMER2_COMPA_vect) {  //This ISR toggles shutdown between the 2MAX7221's
  if(maxInShutdown==RED){
    lc.shutdown(GREEN,true);  // The order here is critical - Shutdown first!
    lc.shutdown(RED,false);   // . . . Then restart the other.
    maxInShutdown=GREEN;
  }
  else {
    lc.shutdown(RED,true);
    lc.shutdown(GREEN,false);
    maxInShutdown=RED;
  }
}  

void setISRtimer(){  // setup ISR timer controling toggleing
  TCCR2A = 0x02;                        // WGM22=0 + WGM21=1 + WGM20=0 = Mode2 (CTC)
  TCCR2B = 0x05;                // CS22=1 + CS21=0 + CS20=1 = /128 prescaler (125kHz)
  TCNT2 = 0;                            // clear counter
  OCR2A = ISR_FREQ;                     // set TOP (divisor) - see #define
}

void startISR(){  // Starts the ISR
  TCNT2 = 0;                            // clear counter (needed here also)
  TIMSK2|=(1<<OCIE2A);                  // set interrupts=enabled (calls ISR(TIMER2_COMPA_vect)
}

void stopISR(){    // Stops the ISR
  TIMSK2&=~(1<<OCIE2A);                  // disable interrupts
}


/////////   Wrappers for LedControl functions . . . //////////
void SetLed(byte Color, byte Row,byte Col, byte State){
  stopISR();            // disable interrupts - stop toggling shutdown when updating
  lc.setLed(Color,Row,Col,State);
  startISR();           // enable interrupts again
}

void SetRow(byte Color, byte Row, byte State){
  stopISR();            // disable interrupts - stop toggling shutdown when updating
  lc.setRow(Color,Row,State);
  startISR();           // enable interrupts again
}

void SetColumn(byte Color, byte Col, byte State){
  stopISR();            // disable interrupts - stop toggling shutdown when updating
  lc.setColumn(Color,Col,State);
  startISR();           // enable interrupts again
}

void ClearMatrix(){
  stopISR();            // disable interrupts - stop toggling shutdown when updating
  lc.clearDisplay(GREEN);
  lc.clearDisplay(RED);
  startISR();           // enable interrupts again
}

If you have seen the videos I made for you, please let me know so I can take them down.

I have tried to only use the sample code that you provided on SRI

Just curious what is SRI?

Hi BorHogan,

Really thanks for your help indeed. Yes definately I won't give up to try using two max IC, but just need to think of workaround just in case it still can't sort out. I can put this as phase 2 as my on-going research project as I got few matrix and IC so I can work on those.

The comment that you made in the code is really useful, just help more in understanding the logic.

1) I am using the following, do you think is the issue? 7219CNG, as I know there are several 7219 (MAX7219CNG: http://uk.rs-online.com/web/search/searchBrowseAction.html?method=searchProducts&searchTerm=max7219&x=0&y=0) 2) To clearly indicate the LED matrix pin, there are total 12 pins up and 12 pins bottom. I tested out each pin from the LED red/green color go with 5V, and the row go with GND, so as to identify which one is anode/cathode => link with DIG and SEG from the IC. I don't know if this is the right method, as there is no direct mapping on each of the pin in the matrix. 3) but in any case I think is correct approach on item 2 above, because before I have wrongly connect the DIG and SEG to the matrix, it turns out all the LED light up. Just swapping this will make the LED function properly by using the LEDControl library test. So I believe hardware wiring, it should be fine with those connection rows/cols. 4) for digit In, Clock, Out, Load => this is pretty simple, just OUT link to IN from another IC. others just go to digital pin in Arduino. => so base on above 1,2,3,4 if I made it correctly, I just can't think of any issue despite of the hardware mismatch.

p.s yes the video I have already view it, much thanks :) but it seems better stay on the internet such that people can refer to the code and visual result => this can help much in understanding and resolving similar issues from other members in this forum? Just suggestion anyway...

soon, Just to answer your last questions . . .

Yes, the MAX7219 you have is fine. The letters after have to do with lead free, temp, etc.

The matrix you have has the same pinouts as the one I use. http://www.sparkfun.com/datasheets/Components/SanYoung-Medium-RG.pdf So we are both using pretty much the same hardware. I also assume that we have both run the same software.

I know you feel like the wiring is OK, but there are a lot of wires! If just one is wrong you get some real wacky results.

Beyond that my last suggestions are to double check that the Iset resistors are really the value you think they are (20K).

Also, in your modified code I gave you, note that I use different pins - LedControl lc=LedControl(10,9,8,2); It would be easy to try that.

Finally, note that in my video your arrow points up. (The top of the matrix is on the upper left.) If you have other expectations, then it might point at the problem.

BroHogan