Daisy chaining multiple max7219 chips

I have a rough idea on how to daisychain multiple max7219 chips, but all my efforts tonight didn't seem to produce any result. Also, what changes to the code should i make to accomodate the extra chips? It's one for each layer of my 4x4x4 LED matrix (i built a smaller one as a prototype).

Also, others attempting this might find this diagram useful.

Regards

Alex

I've never used one, but glancing at the data sheet it looks as if you must send out data to all MAX7219s with every data transfer, sending data for the chip farthest from the CPU out first. E.g, if you have device A connected to the arduino and device B daisychained from device A, you'd start an SPI transfer and send the data for device B (which would temporarily reside in device A), then send the data for device A. Daisy chaining in effect makes a single logical device that's a wider version of the original (if that makes any sense).

Of course, if you aren't planning on using more than a few devices you've got enough pins to wire each device individually and not mess with the daisy chaining, but I'm sure you already thought of that.

-j

hi,

wiring really isn't a big deal. just connect all max7219 to vcc, ground and the common clock signal from your arduino.

the first chip's data-in is connected to your arduino. each following chip's data-in has to be connected to the data-out of the previuos max7219.

if you need help on the code side:
basically each chip expects (and can only hold)16 bits of data as a command (8bits register + 8 bits data). if you send more than 16 bits, the bits which you sent first will be shifted out to the data-out. meaning a chip will pass the message to the next max7219.

lets say command A (for the FIRST max chip) would be

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

and message B (for the second max7219 in your chain)

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

just send message B first, then message A and then latch the data. (like "kg4wsv" already wrote above)

-> 0000000000000000,1111111111111111

after the 16th bit is sent (that's the last '1' in my example) the first chip will start to output on it's data-out pin, meaning it will pass the first command to the next chip (at the same time "forgetting" this bit).

it's the same for 3 or more

hej,

some how i fixed a code to daisychain multiple max7219, have a look, it is working some how but there still some buggs, some times some max7219 just die, and i never just more then 4 max7219, at the end with 2 max7219 it works with out any problems so maybe i got some elektronic based problems,

please wirte a post or a mail if you noticed some mistakes in the code

/* code for max 7219 from maxim, 
reduced and optimised for useing more then one 7219 in a row,
______________________________________
 
 Code History:
 --------------
 
The orginal Code where written for the wiring board by:
 * Nicholas Zambetti and Dave Mellis
 * Interaction Design Institute Ivrea
 * Dec 2004
 * http://www.potemkin.org/uploads/Wiring/MAX7219.txt
 
The first modification did:
 * Marcus Hannerstig
 * 2006
 * K3, malmö högskola
 * http://www.xlab.se | http://arduino.berlios.de

This Version is modified by:
 * tomek ness
 * Jan 2007
 * FH-Potsdam
 * http://design.fh-potsdam.de   
______________________________________

-befor sending data make shure that the load is HIGH, 
-fill all the max7219 with data. (begin with the last one)
-set the load to LOW and to HIGH again, so you will upload the data

* take care with the initiation you have to send every part to every max7219 and then upload it.
so for example if you have 5 max7219, you have to send the scanLimit 5 times befor you load it, 
other wise not every max7219 will get the shit. maxInUse is keeping track of this, 
just tell him how many max7219 you are uesing
*/


int dataIn = 2;
int load = 3;
int clock = 4;

int i = 0;    // just a varialble
int e = 0;    // just a varialble
int f = 0;

int c = 0;
int c2= 0;

int maxInUse = 4;    //here you have to change this varialbe to how many max 7219 you want to use


  // 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      = 0x08;
byte max7219_reg_digit7      = 0x01;
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
    }else{
      digitalWrite(dataIn, LOW);  // send 0
    }
    digitalWrite(clock, HIGH);  // tock
    --i;                     // move to lesser bit
  }
}
////////////////////////////


void maxPut (byte reg, byte col) {    // use this 

//data = ((data & 0x01) * 256) + data1 >> 1;
//data = (data << 1) + ((data >> 7) & 0x01); 
putByte(reg);  // specify register
putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
}

void maxIni (byte reg, byte col) {    // put the initialisation to all the max 7219 in the system
  int c = 0;
  digitalWrite(load, HIGH);
  for ( c =1; c<= maxInUse; c++) {
    maxPut(reg, col);   // use all 8 columns
    }
  digitalWrite(load, LOW);
  digitalWrite(load,HIGH);
}

void setup () {


  pinMode(dataIn, OUTPUT);
  pinMode(clock,  OUTPUT);
  pinMode(load,   OUTPUT);
  
  beginSerial(9600);
  digitalWrite(13, HIGH);  
  //////////////////////////////////////////////initiation of the max 7219
  
  
  maxIni(max7219_reg_scanLimit, 0x07);      
  maxIni(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
  maxIni(max7219_reg_shutdown, 0x01);    // not in shutdown mode
  maxIni(max7219_reg_displayTest, 0x00); // no display test
   for (i=1; i<=8; i++) {    // empty registers, turn all LEDs off 
    maxIni(i,0);
  }
  maxIni(max7219_reg_intensity, 0x0f & 0x0f);    // the first 0x0f is the value you can set
  
  }
  
  void loop () {
   
   

 //------------------------------------all doing the same: 3 led on and more
  

  printString("los");   
  for (i=1; i<=8; i++) {    // all max7219 doing the same shit (fill up led by led at every max7219 at the same time)
        //c = 1;
        //for (e=1; e<=8; e++) {
        digitalWrite(load,HIGH);  
        maxPut(i, 193);            //56, 192 is working
        maxPut(i, 193);            //60, 57 not
        maxPut(i, 193);
        maxPut(i, 193);
        digitalWrite(load, LOW);
        //delay(1);
        digitalWrite(load,HIGH);
        delay(200);
        
   }
  delay(2000);
    

  for (i=1; i<=8; i++) {    // a longer way to clean the dispaly
        digitalWrite(load,HIGH);  
        maxPut(i, 0);
        maxPut(i, 0);
        maxPut(i, 0);
        maxPut(i, 0);
        digitalWrite(load, LOW);
        //delay(1);
        digitalWrite(load,HIGH);
        delay(200);
  }

  
  
  delay(2000);
  
  }

Hey Tomek,

Can I use that code to daisy-chain the chips? Anybody have any suggestions, I'm not very good with coding, or understanding exactly how the data should be arranged...

Also, does anyone have any interactive apps for the light matrix? It's be interesting to see something like a music visualizer or maybe a game of pong, I'd code it myself but unfortunately my skills aren't up to scratch!

Regards,

Alex

I have a few laying around. I'll try very soon and see what I can do. Do they die mostly when they are all on, or at any rate? My first guess would be current, what are you using as power source?

the real weird thing is: it works perfect if i just want to light up one led at each of the 4 max7219, but if i want to light up more then 4 LED in a row the 2-4 max7219 gets fu**ed up and just the first one keeps one working.

today i tryed it with a pretty good powersupply (a voltkraft, where you can select the voltage, and a power up to 3 Amper), but it didn't worked...

i also tryed to ampliefy the clock and load singal with powertransistors (irf520), but this also doesn't worked out,

for this try out i had to invert the code for the clock and load, but of course NOthing happens

tack
tomek

hi Tomek

one thought is that perhaps the power supply is full of noise from the 7219 switching through the rows and columns so quickly. Do you have some capacitors near its power suply pins? Something like .1uF on each is usually good, and for high current loads I add a 10uF or 22uF also.

hej Daniel,

could you please do a quick drawing or scematic how and where to conect them, i didn't got it,...

tack
tomek

hi Tomek,

if noise is the problem, it's easy to find out. Just place a .1uF capacitor between gnd (pin 9) and VCC (pin 19) on each 7219. It's also a good idea to put a 33UF or 100 Uf or similar capacitor across the main LED power supply.

D

hej daniel,

thx, now i got it to work,
today i was able to controll 5 max7219 with the help of your capacitors and the powertranssitors;
the only problem i have now, is that this 5 guys sucks 3 amper....

hey

that is good news... you can never have too many .1UF or 100UF capacitors on your supply lines. I always design a ton of them into my circuits, as it makes for one less thing to worry about.

D

Hi there!
In these days I'm doing the same with three max7219 controlled from max/msp and I found the same problems I read in these posts. So I followed all your instructions but I don't understand some things about how to connects the components you said. For instance: Do I have to add a transistor for booth the Clock and the Load pin?

If some of you could send me a little sketch of the circuit that would be really helpfull!!

Thanks!