Pages: [1]   Go Down
Author Topic: Max 7219 + Matrix  (Read 430 times)
0 Members and 1 Guest are viewing this topic.
Malmoe
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

we´re having problem to get our matrix up and running!

We have linked the arduino to max7291 and then to the matrix (ELM-2882GWA). We´re pretty sure that we have connected everything right.

We´re using this code:
Code:
int dataIn = 2;
 int load = 3;
 int clock = 4;

int maxInUse = 1; //here you have to change this varialbe to how many max 7219 you want to 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      = 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) {


  //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 maxSingle( byte reg, byte col) { //maxSingle is the more easy way while just useing one max7219


  digitalWrite(load,HIGH);            // this funktion will take care of uploading the data
  putByte(reg);  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data  
  digitalWrite(load, LOW); // and load da shit
  digitalWrite(load,HIGH);
  
}


void maxAll (byte reg, byte col) { // put the reg/col information 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 maxOne(byte maxNr, byte reg, byte col) { //maxOne for controling one max7219 of the bulk


  int c = 0;
  digitalWrite(load, HIGH);

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

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

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

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


void setup () {


  pinMode(dataIn, OUTPUT);
  pinMode(clock,  OUTPUT);
  pinMode(load,   OUTPUT);

  beginSerial(9600);
  digitalWrite(13, HIGH);  
  //////////////////////////////////////////////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, 0x01);    // 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(e,0);
  }
  maxAll(max7219_reg_intensity, 0x0f & 0x0f);    // the first 0x0f is the value you can set
                                                  // range: 0x00 to 0x0f
}


void loop () {


  //------------------------------------ if you use just one max7219 he should look like this
  
   maxSingle(1,1);                       //  + - - - - - - -
   maxSingle(2,2);                       //  - + - - - - - -
   maxSingle(3,4);                       //  - - + - - - - -
   maxSingle(4,8);                       //  - - - + - - - -
   maxSingle(5,16);                      //  - - - - + - - -
   maxSingle(6,32);                      //  - - - - - + - -
   maxSingle(7,64);                      //  - - - - - - + -
   maxSingle(8,128);                     //  - - - - - - - +

  delay(2000);

}



All the lights on the matrix are lighten, but the code is supposed to result in a diagonal line.

can anyone find our problem?  :-/


Cheers
Henrik .... etc.
« Last Edit: March 23, 2007, 12:29:09 pm by Henrik » Logged

malmö / berlin
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
fhp&gt;--vs--&lt;k3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hej,

the code should work, maybe you connect the matrix the wrong way, according to the datasheet the ground from the LED (ctahtode) should be connected to the dig0-7 (pin 2,3,5-8,10,11)
("Eight-Digit Drive Lines that sink current from the display common cathode. The MAX7219 pulls the digit outputs to V+ when turned off. The MAX7221's digit drivers are high-impedance when turned off.")
and the supply side LED+ (annode)  have to be connectet  to the segA-D, DP ( pin14-17, 20-23)
(" Seven Segment Drives and Decimal Point Drive that source current to the display. On the MAX7219, when a segment driver is turned off it is pulled to GND. The MAX7221 segment drivers are high-impedance when turned off.")

furthermore if you connect the matrix the otherway arround, it will alway light, because for example when a dig pin (at the max7219) is turned off it will pulled from ground to 5v and for the sig it is the otherway around.

so maybe this is your problem, but otherwise maybe you should post some fotos and discribe your problem a little bit more

als the best
tomek
Logged

Pages: [1]   Go Up
Jump to: