Pages: 1 [2]   Go Down
Author Topic: MAX7219 with Arduino  (Read 2693 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

#include <LiquidCrystal.h>  //Used for the LCD Module   HAVE TO GO TO SKETCH-> Import Library...

#include "LedControl.h"  // This library helps with using the 7-segment driver(MAX72XX)

#include <SPI.h>


/*

pin 12 is DataIn

pin 11 is CLK

pin 10 is LOAD (Latch)


*/
//Constants wont change


const int Data = 12;        // Data line into the chip

const int CLK =  11;       //CLOCK Signal for the chip

const int LOAD = 10;       //The pin to control the latch or load value on chip

const int driver_num = 1;  //number of MAX72XX's we are linked or using in total


LedControl lc=LedControl(Data,CLK,LOAD,driver_num);  //this line assigns the pins to what we have labeled in the comment block above

                                                    //The last number states how many devices aka how many MAX72XX's  Note: the lc is just a variable that is created



/*

Gets the max number of devices attached to the LedControl

Returns the number of devices attached

*/

          //int LedControl::getDeviceCount();




// Variables that will change:  AKA software variables



        int milliseconds = 0;  //will keep track of milliseconds

        int countOnes = 0;  // will keep track of seconds

        int countTwos = 0;  // will keep track of tens of seconds

        int countThrees = 0;  // will keep track of minutes

        int countFours = 0;  // will keep track of tens of minutes

        int countFives = 0;  // will keep track of hours

        int countSix = 0;  // will keep track of tens of hours

        int amPM = 0;      // low for AM, High for pm



//INTERRUPT SERVICE ROUTINE FOR TIMER 1



    ISR(TIMER1_OVF_vect) {

              TCNT1 = 0xC180;      //this resets the timer to this preloaded value after every overflow

              milliseconds = milliseconds + 1;    //increments this 1 each time an overflow occurs

                          }


void setup() {                   //Code to be run 1 time goes here


//*******************************************TIMER INITIALIZATION CODE************************************************************

TIMSK1 = 0x01;

TCCR1A = 0x00;

TCNT1 = 0xC180;        //Reload value of 49,536, so we can get a 1millisecond clock...

TCCR1B = 0x01;        //No prescaler  (page 137 Atmel Datasheet)

//***********************************************************************************************************************************


//wakes up the MAX72XX from power-saving mode

lc.shutdown(0,false);



//set a medium brightness for the display

lc.setIntensity(0,8);  //this sets intesity for digits 0 to 3



//clear display

lc.clearDisplay(0);


}




void loop() {                    //Infinate Loop



//BEGINING OF MAIN TIMER SECTION

      if(milliseconds == 1000){

                            milliseconds = 0;

                            countOnes += 1;  //after 1000 milliseconds, seconds will be incrmented 1

                              }

      if(countOnes == 10){

                            countOnes = 0;

                            countTwos +=1;

                          }



      if(countTwos == 6){

                            countTwos =0;

                            countThrees += 1;  //means that when 60 seconds pass, minutes is incremented 1

                           


                          }



      if(countThrees == 10){

                            countThrees = 0;      // if 10 minutes goes buy, this goes to zero and the ten minutes spot gets incrmented one

                            countFours += 1;     // tens of minutes

                           



                          }



      if(countFours == 6){

                            countFours = 0;    // Sixty seconds equal 1 hour

                            countFives += 1;  // hours is incremented

                           



                          }



      if(countFives == 10){

                            countFives = 0;    //count to 9 hours, then when get to 10 hours the place gets rolled over

                            countSix += 1;

                           



                          }



      if(countSix == 2){

                            countSix = 0;    //This can only get to the vaule of 0 or 1 any higher, it resets



       

                  if(amPM == 1){



                                  amPM = 0;    // this code inverts PM to am or vis versa



                                }



                  else{



                                  amPM = 1;



                      }



                        }    // end of countSix



lc.setDigit(0,0,countThrees, false);//seconds place output
                                                                // device 0(only 1 Max72xx) , digit(0), number to output and then false
delay(1);


lc.setDigit(0,1,countFours, false);  // device 0(only 1 Max72xx) , digit, number to output and then false

delay(1);
 
 
 lc.setDigit(0,2,countFives, false); //hours place output
                                                                // device 0(only 1 Max72xx) , digit(2), number to output and then false
delay(1);   


lc.setDigit(0,3,countSix, false); //tens of hours place output
                                                              // device 0(only 1 Max72xx) , digit(3), number to output and then false
delay(1);




   

}          //END OF LOOP       



//END OF MAIN TIMER SECTION




above is my code, attached are some pics of what i am getting, for some reason my dots are lit up, but the other stuff isnt lit up correctly, as you can see they all look the same and dont display numbers

also i have questions in the code that relates to that LEDCONTROL.h library

" lc.setDigit(0,0,countThrees, false);//seconds place output  "
the line above for example, what does the false mean? and
does the 1st digit mean im talking to only 1 max72xx and the 2nd digit, means what acctual digit im programing correct?


Thanks,


Zack


* IMAGE_032.jpg (935.17 KB, 1536x2048 - viewed 29 times.)

* IMAGE_033.jpg (876.97 KB, 1536x2048 - viewed 24 times.)

* IMAGE_075.jpg (1091.91 KB, 1536x2048 - viewed 27 times.)

* IMAGE_106.jpg (765.88 KB, 2048x1536 - viewed 28 times.)
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1232
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi-

while I havent messed with the ledControl lib for a while now.. (or been in the MAX72XX datasheet)

I think I remember something about blanking/initializing the chips before starting.. (should be outlined in the tut/library)

yes the first parameter means the chip you want to target I believe..you can have up to 8 daisy chained I believe..

the second is the 'led' you are targeting..   3rd parameter is the state of the on or off..


you are using the 7xsegment led functions though.. which looks as if it takes an additional parameter...

You'd have to refer back to the documentation as I dont recall the 7-segment functions as I havent used them.

Logged


Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@imzack

In your code, this :

Code:
#include "LedControl.h"  // This library helps with using the 7-segment driver(MAX72XX)

#include <SPI.h>

Can not be use at the same time. A confic here. I did look at LedControl.cpp file. The library use shiftOut() to send data to the max7219. So it conflic the SPI library. Pin 13 is the data and I think pin 12 is the clock. Just keep LedControl.h  Delete the SPI.h

Quote
Techone, MSBfirst, is that a variable that arduino knows?  or is that something else?

Yes, the Ardiuno IDE know what is MSBFIRST or LSBFIRST. It is use for shiftOut( datapin, clockpin, MSBFIRST, value_to_send_in_byte );  MSBFIST mean the last bit of the data to be send get out of the Arduino datapin first.

Example :  1011 - > number 11. So the Ardiuno send the bits in that order : Last bit out --> 1 -- > 1 --- >  0 --> 1 <-- First bit out
 
Logged

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

Thank you, I took out the SPI library at the top.

However, it didnt do anything different.

Below is the code that im using right now...

Code:

#include <LiquidCrystal.h>  //Used for the LCD Module   HAVE TO GO TO SKETCH-> Import Library...

#include "LedControl.h"  // This library helps with using the 7-segment driver(MAX72XX)



/*

pin 12 is DataIn

pin 11 is CLK

pin 10 is LOAD (Latch)


*/
//Constants wont change


const int Data = 12;        // Data line into the chip

const int CLK =  11;       //CLOCK Signal for the chip

const int LOAD = 10;       //The pin to control the latch or load value on chip

const int driver_num = 1;  //number of MAX72XX's we are linked or using in total


LedControl lc=LedControl(Data,CLK,LOAD,driver_num);  //this line assigns the pins to what we have labeled in the comment block above

                                                    //The last number states how many devices aka how many MAX72XX's  Note: the lc is just a variable that is created



/*

Gets the max number of devices attached to the LedControl

Returns the number of devices attached

*/

          //int LedControl::getDeviceCount();




// Variables that will change:  AKA software variables



        int milliseconds = 0;  //will keep track of milliseconds

        int countOnes = 0;  // will keep track of seconds

        int countTwos = 0;  // will keep track of tens of seconds

        int countThrees = 0;  // will keep track of minutes

        int countFours = 0;  // will keep track of tens of minutes

        int countFives = 0;  // will keep track of hours

        int countSix = 0;  // will keep track of tens of hours

        int amPM = 0;      // low for AM, High for pm



//INTERRUPT SERVICE ROUTINE FOR TIMER 1



    ISR(TIMER1_OVF_vect) {

              TCNT1 = 0xC180;      //this resets the timer to this preloaded value after every overflow

              milliseconds = milliseconds + 1;    //increments this 1 each time an overflow occurs

                          }


void setup() {                   //Code to be run 1 time goes here


//*******************************************TIMER INITIALIZATION CODE************************************************************

TIMSK1 = 0x01;

TCCR1A = 0x00;

TCNT1 = 0xC180;        //Reload value of 49,536, so we can get a 1millisecond clock...

TCCR1B = 0x01;        //No prescaler  (page 137 Atmel Datasheet)

//***********************************************************************************************************************************


//wakes up the MAX72XX from power-saving mode

lc.shutdown(0,false);  //turns off shutdown mode, so you can display stuff


//set a medium brightness for the display

lc.setIntensity(0,14);  //this sets intesity for digits 0 to 3


//clear display

lc.clearDisplay(0);




}




void loop() {                    //Infinate Loop
//BEGINING OF MAIN TIMER SECTION

      if(milliseconds == 1000){

                            milliseconds = 0;

                            countOnes += 1;  //after 1000 milliseconds, seconds will be incrmented 1

                              }

      if(countOnes == 10){

                            countOnes = 0;

                            countTwos +=1;

                          }



      if(countTwos == 6){

                            countTwos =0;

                            countThrees += 1;  //means that when 60 seconds pass, minutes is incremented 1

                          }



      if(countThrees == 10){

                            countThrees = 0;      // if 10 minutes goes buy, this goes to zero and the ten minutes spot gets incrmented one

                            countFours += 1;     // tens of minutes

                          }



      if(countFours == 6){

                            countFours = 0;    // Sixty seconds equal 1 hour

                            countFives += 1;  // hours is incremented

                          }



      if(countFives == 10){

                            countFives = 0;    //count to 9 hours, then when get to 10 hours the place gets rolled over

                            countSix += 1;

                          }



      if(countSix == 2){

                            countSix = 0;    //This can only get to the vaule of 0 or 1 any higher, it resets



       

                  if(amPM == 1){



                                  amPM = 0;    // this code inverts PM to am or vis versa



                                }


                  else{


                                  amPM = 1;

                      }



                        }    // end of countSix



//lc.setDigit(0,0,0x04, false);//seconds place output  countThrees
                                                                // device 0(only 1 Max72xx) , digit(0), number to output and then false
delay(2000);


lc.setDigit(0,1,countFours, false);  // device 0(only 1 Max72xx) , digit, number to output and then false

delay(2000);
 
 
 lc.setDigit(0,2,countFives, false); //hours place output
                                                                // device 0(only 1 Max72xx) , digit(2), number to output and then false
delay(2000);   


lc.setDigit(0,3,countSix, false); //tens of hours place output
                                                              // device 0(only 1 Max72xx) , digit(3), number to output and then false
delay(2000);

lc.setChar(0,0,'0',false);

delay(2000);

lc.shutdown(0,true);  //turns off shutdown mode, so you can display stuff
   
delay(2000);

lc.shutdown(0,false);  //turns off shutdown mode, so you can display stuff

delay(2000);
   
lc.setChar(0,0,'1',false);

delay(2000);
   
lc.setChar(0,0,'2',false);

delay(2000);
   
lc.setChar(0,0,'3',false);

delay(2000);
   
lc.setChar(0,0,'4',false);

delay(2000);
   
lc.setChar(0,0,'5',false);

delay(2000);
   
lc.setChar(0,0,'6',false);

delay(2000);
   
lc.setChar(0,0,'7',false);

delay(2000);
   
lc.setChar(0,0,'8',false);

delay(2000);
   
lc.setChar(0,0,'9',false);

delay(2000);
   
lc.setChar(0,0,'a',false);

delay(2000);
   
lc.setChar(0,0,'b',false);

delay(2000);

lc.setChar(0,0,'c',false);

delay(2000);
   
lc.setChar(0,0,'d',false);

delay(2000);
   
lc.setChar(0,0,'e',false);

delay(2000);
   
lc.setChar(0,0,'f',false);

delay(2000);
   




}          //END OF LOOP       



//END OF MAIN TIMER SECTION










As seen at the bottom of my code i attempt to go through all the characters... but what i can see is no numbers, but the decimal points stay lit at all times, untill it enters shutdown mode, that works.  then upon shutdown mode being turned off, the decimal points are lit again for and still nothing on the other segments...

Any ideas?

Also i will draw up a hardware diagram to see if that might be wrong too... i think its correct however, since ive gone through it multiple times.

Thanks agian!

Zack
Logged

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

Here is a diagram of what i have hooked up...

I also have a iset of 9.5k

other than that idk if i have it set up correctly or not... since it is acting odd

if someone could take a look it would be greatly appricated!

thanks,

Zack


* Diagram.png (27.4 KB, 1071x493 - viewed 25 times.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26378
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

Doesn't the MC1488 invert the signal? So when the MAX7219 drives high on the DIG lines, you end up driving the DIGx pins low?
And the same for the ULN2803 - when the MAX7219 drives high on the segment lines, the segment lines get driven low?
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.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let get the facts about the MAX7219.

Hardware :   The segments are : a, b, c, d, e, f, g, DOT   A HIGH / 1 is generated from those segments. <--- see commun cathode
The digits are a LOW / 0 when a digit is selected.  Because a HIGH to LOW will flow the current, but a HIGH to HIGH will not.

So let get this principle in mind. To drive a bigger currents - leds type, let look at a commun anode type display, so you simply apply the same principle.

I don't know what is the type of config your display is commun anode  or commun cathode. Until you know the config, than let figure out a way to use transistors / drivers to control more currents to use a HGH - LOW <-- MAX7219 principles first. As long you are aware that principle, than your code will work. ( in theory )  smiley-roll  And one little trick here, use an INVERTER gate if you have too, that solution may work.

An NOT gate --> 0 --> 1 or 1 --> 0  See the 74LS04. Just use a octal NOT gate.

Software : The MAX7219 have a Decode Mode Register = 0x09  A No Decode : Can display what ever you want from the segments. Check the datasheet. page 8. Example : Let display 01101100. You simply send this data into the register data to be display.That is good for leds matrix.  Code B will display according to Table 5. The register data is simply a number from 0 to 9 and it will display a number according to table 5. But the digits being selected , well, a LOW will "select" that digit by sending a LOW. So you are stuck with this.

I am sorry  you may have to re-design the circuit to accominate the 7219.
                 
Logged

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

@CrossRoads  The max7219 i believe sinks the current in the Digx.  so when it is hooked up to the MC1488p line driver, it will invert it, and supply the 7-segment with the 12 volts at Vcc.

Also here are the 7-segments that i got from sparkfun....    http://www.sparkfun.com/products/8530   

ill have to take a look at the decode mode register too...  i am using the ledcontrol.h library, ill have to figure out how to write to registers for the max7219
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26378
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

Okay, you're using a common-cathode driver to control a common-anode display.
You're sending the high-output segment lines into an open-collector driver, the MAX7219 high-out creates a low-output from the ULN2803.
Youlre sending the low-output digit control lines into an invertor trying to push current into the cathodes of LEDs.

You need to read this application note

http://pdfserv.maxim-ic.com/en/an/AN1196.pdf

to use the MAX7219 with a high-voltage common-anode part.
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 [2]   Go Up
Jump to: