Pages: [1]   Go Down
Author Topic: MAX7219 and 51 MCU 8x8 LED matrix  (Read 6364 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, I am new at this. I have an ARDUINO UNO and purchased a kit containing a board and an 8x8 led matrix and a MAX7219. Once assembeled, and the matrix plugged in, it gives me a 5 pin input "VCC, GND, DIN, CS and CLK" I have TWO problems:

1- Apart from the Power and Ground, I can't find the corresponding pins on the ARDUINO.

2- I have found several SKETCHES on this and other sites written to run an 8x8 matrix using a MAX7219 but when I try to compile them, I get errors:
sketch_nov04a.cpp:4:24: error: LedControl.h: No such file or directory
sketch_nov04a:13: error: 'LedControl' does not name a type

Can anyone help a new guy?

Thanks

Logged

Southport UK
Offline Offline
Full Member
***
Karma: 1
Posts: 195
Been at it a long time...still learning every day.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi mate.

Sounds like you are missing a library...LedControl.h is a header file which needs to be in the path of your sketch.

FYI:
     CLK = clock pulse source
     DIN = data in
     CS = chip select

you really need to post which sketch you are using and how you have everything wired up.  smiley-wink
Logged

Sponge.
I'm allowed to have it 'cos it's not sharp.

Raleigh, NC.
Offline Offline
Full Member
***
Karma: 0
Posts: 129
Addicted to Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

These are SPI Pinouts.....or serial peripheral interface.....on the Uno , you can google uno board and the site has the info there. Cs also can be SS, MOSI is data, SCK is clock.....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the link to what I purchased and assembeled:

http://www.ebay.ca/itm/MAX7219-Dot-matrix-module-MCU-control-Display-module-DIY-kit-Arduino-/271059097882

This is the Sketch I obtained from this site (which compiles properly) and that I am using (I know that the pin assignment is not correct):

/* code for max 7219 from maxim,
reduced and optimised for useing more then one 7219 in a row,
______________________________________

 Code History:
 --------------

The orginal code was 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

First modification by:
 * Marcus Hannerstig/  K3, malm� h�gskola /2006
 * http://www.xlab.se | http://arduino.berlios.de

This version is by:
 * tomek ness /FH-Potsdam / Feb 2007
 * http://design.fh-potsdam.de/

 * @acknowledgements: eric f.

-----------------------------------

General notes:


-if you are only using one max7219, then use the function maxSingle to control
 the little guy ---maxSingle(register (1-8), collum (0-255))

-if you are using more then one max7219, and they all should work the same,
then use the function maxAll ---maxAll(register (1-8), collum (0-255))

-if you are using more than one max7219 and just want to change something
at one little guy, then use the function maxOne
---maxOne(Max you wane controll (1== the first one), register (1-8),
collum (0-255))

/* During initiation, be sure to send every part to every max7219 and then
 upload it.
For example, if you have five max7219's, you have to send the scanLimit 5 times
before you load it-- other wise not every max7219 will get the data. the
function maxInUse  keeps track of this, just tell it how many max7219 you are
using.
*/

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

int maxInUse = 1;    //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
    }else{
      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   
// and load da shit
  digitalWrite(load,HIGH);
}

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,HIGH);
}

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
  }

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


void setup () {


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

  Serial.begin(9600);
  digitalWrite(clock, 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 it 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);                     //  - - - - - - - +

  */
  //if you use more than one MAX7219, it should look like this

  /*
  maxAll(1,1);                       //  + - - - - - - -
  maxAll(2,3);                       //  + + - - - - - -
  maxAll(3,7);                       //  + + + - - - - -
  maxAll(4,15);                      //  + + + + - - - -
  maxAll(5,31);                      //  + + + + + - - -
  maxAll(6,63);                      //  + + + + + + - -
  maxAll(7,127);                     //  + + + + + + + -
  maxAll(8,255);                     //  + + + + + + + +
  */

  //

  //if you use more then one max7219 the second one should look like this


  maxOne(2,1,1);                       //  + - - - - - - -
  maxOne(2,2,2);                       //  - + - - - - - -
  maxOne(2,3,4);                       //  - - + - - - - -
  maxOne(2,4,8);                       //  - - - + - - - -
  maxOne(2,5,16);                      //  - - - - + - - -
  maxOne(2,6,32);                      //  - - - - - + - -
  maxOne(2,7,64);                      //  - - - - - - + -
  maxOne(2,8,128);                     //  - - - - - - - +


  //
  delay(2000);

}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34180
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1- Apart from the Power and Ground, I can't find the corresponding pins on the ARDUINO.
I assume that this is still your question.

This bit of the code tells you:-
Code:
int dataIn = 2;
int load = 3;
int clock = 4;
So:-
Din -> Pin 2
Cs -> Pin 3
Clk -> Pin 4


Next time use code tags when posting code!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all your help. I have seen similar sketches that use pins 10' 11' 12. Which from what I gather are analog whereas the 2, 3, 4 are digital. Clearly this will require going back to square one for me so that I am certain that everything works properly electronically on my MAX7219 and then tackle the sketch.

Thanks.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

0-13 are all digital pins.
A0-A5, are analog, and may be used as digital pins 14-19.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34180
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have seen similar sketches that use pins 10' 11' 12.
Yes those use the inbuilt SPI interface to talk to the chip. If you do not use this then you have to bit bang the SPI interface like the sketch you posted.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pins 10-11-12 is bitbanging. (SS-MOSI-MISO)
Pins 10-11-13 are needed for actual SPI. (SS-MOSI-SCK)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: