...

View Full Version : MAX 7219 help



lordsneed
11-29-2011, 10:07 PM
I have MAX7219 led drivers trying to drive 3 LED matrices of 6x6. My final goal is to create a LED clock. I found some demo code online here:

http://www.arduino.cc/playground/LEDMatrix/Max7219

I believe my wiring is correct. Dig to the cathodes and Seg to anodes. None of the LEDs light up however when I upload the code to the arduino. I really need some help as to why it is not working. I appreciate all help and apologies if this is not on the right category, this is my first time on here.

Fou-Lu
11-29-2011, 11:08 PM
What language are you writing in? Java doesn't seem like one I'd choose, look into C or a lower level language to perform the task of physical control. I've never written anything that interacts with an external circuitry before, but I somehow doubt that Java will be the language of choice.
I don't follow links from work though, so you can go ahead and post the code here to see what it is.

alykins
11-30-2011, 12:00 AM
that is a PIC- it has assembly language... see here (http://ee.cleversoul.com/max7219-source.html) for reference... it isn't Java. They offer examples read the release notes in the link for how they wrote their's... this shouldn't be in Java- should be in Computer Programming... I will say I don't know a lot of other people here besides myself who would know what this is though- I would look into an EE forum. It has been a few years since I've coded PICs

Fou-Lu
11-30-2011, 12:08 AM
That looks to me like its written in C. No matter, it definitely isn't java. I'm sure its doable in java as well, but I sure wouldn't recommend it.
Moving from Java forum to Computer Programming

lordsneed
11-30-2011, 01:15 AM
/* 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 = 4; //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
digitalWrite(load, LOW); // and load da ****
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, LOW);
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
}

digitalWrite(load, LOW); // and load da ****
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 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);

}

oracleguy
11-30-2011, 04:32 AM
that is a PIC- it has assembly language... see here (http://ee.cleversoul.com/max7219-source.html) for reference... it isn't Java. They offer examples read the release notes in the link for how they wrote their's... this shouldn't be in Java- should be in Computer Programming... I will say I don't know a lot of other people here besides myself who would know what this is though- I would look into an EE forum. It has been a few years since I've coded PICs
Actually aren't all Arduino's AVRs not PICs?

As to the posters question start with a much more basic test program. Instead of trying to do anything super complicated just write a program that turns all the LEDs on and off one row at a time. That way you know everything is wired correctly.

alykins
11-30-2011, 04:42 AM
Actually aren't all Arduino's AVRs not PICs?


no clue :D I majored in High Frequency and Control Systems; My PIC xp is dangerous... I went with PLC's post graduation. I think the last PIC I used was 68HC11 which has code like this (http://home.earthlink.net/~tdickens/68hc11/code/lcd.asm)... aside from "assembly" i don't know what language to call that lol...



I think the last PIC I used was 68HC11


no that's not true... I used another PIC for some RFID work but I do not remember what it was.

lordsneed
11-30-2011, 05:00 AM
I did try hooking up just one LED to see if I could get that one to turn on. I have checked my connections many times. I have tested every LED manually to make sure they all work and they do. I just can't get them to turn on through the driver.

+5V on the arduino is going to +5V on the driver
ground is going to ground
Digital pin 2 on the arduino is going to DIN on the driver (pin 1)
Digital pin 3 on the arduino is going to the LOAD (CS (inverted logic)) pin on the driver (pin 12)
Digital pin 4 on the arduino is going to the CLK on the driver (pin 13).

Currently to test the one LED I have the long lead (anode +) connected to the SEG DP pin (pin 22) on the driver.

The short lead (cathode -) is connected to DIG 0 (pin 2) on the driver.

Any insight on this?

alykins
11-30-2011, 08:06 AM
did you check this (http://ee.cleversoul.com/max7219.html) pinout as well?

lordsneed
12-01-2011, 01:41 AM
Yes I did. There is no difference with what they were doing and what I am doing except for the fact that I am using a different microprocessor. I am using a Freeduino. I tried playing with some more code today to try to just get one LED working (using SPI, etc because the MAX7219 can use it). I got some interesting behavior, I currently do not have the code because my colleague has it.

Essentially though, we tried turning a specific pin on and off and we had it print the state to the screen. It would turn on and off, however, the LED would still not light. It lit only temporarily sometimes then shut off again and interestingly enough the LED would light when we moved the wire to different different pins. At one point it would flicker slightly between max brightness and a slightly less bright (had to look kind of closely to notice) at every other pin except the one we programmed to turn on and off. So there is something that's not obvious or that we aren't seeing. I believe it's with the code, I think.

Anyone have any idea how to program the driver and properly turn the pins on and off? I am about 99.9% sure that the problem is with the code as we can get a LED to turn on through the driver, it's just not behaving as it should. Sample code in C/SPI would be appreciated (how to turn on one or a couple LEDS, I can figure out the rest if the explanation is clear enough). I am not asking for someone write the code for the entire thing. Thanks.

alykins
12-01-2011, 02:00 AM
ok i have an idea
hook a scope up to it and see if you are getting anything. You may be trying to drive the LED w/ so little current that it can't light up. you may need to throw it through an amplifier circuit. verify that the pin has a signal on it when you "manually" trigger it in the code...

lordsneed
12-01-2011, 04:18 AM
I can try that but the LEDs do not have a problem lighting/getting the proper current because they can/do light they just didn't follow the behavior. I just tried basic code similar to the one here:

http://tronixstuff.wordpress.com/2010/07/09/review-maxim-max7219-led-display-driver-ic/

I am confused about their drawing though (towards the middle of the page). I understand everything except the numbers drawn in the matrix box. The numbers in the driver box are the pin numbers, but I don't understand what the numbers in the matrix box mean. What do they mean?

That page though is essentially what I am doing except I have a resistor before every LED and it's on a prototype board. The LED driver I have on a breadboard until I get it working. That is essentially what I am doing though. I will try this code (unaltered) without SPI tomorrow to see if that works and make sure I connect everything correctly.

alykins
12-01-2011, 04:47 AM
you are over complicating it... the matrix is if you are trying to make chars similar to his "A" that he has in pictures lower on the page... what you need to do is figure out turning on and off bits to fire LEDs.... once you get that make the code for this logical process


define:
a= seconds "ones" column
b= seconds "tens" column
c= minutes "ones" column
d= minutes "tens" column
e= hours "ones" column
f= hours "tens" column

initialize a=b=c=d=e=f=0
do{
while(trigger == true)
{
if (a== 9 & b!=5) {a=0 & b++}
if (a==9 & b==5 & c!=9) {a=0 & b=0 & c++}
else a++
}
}


you will need to write more pseudo to flow the program out, but essentially you will have an infinite loop that all variables get initialized before dropping into... then you set a trigger based off that clock... the code and triggers are a bit more complex now that i am thinking through it but essentially you do not need a matrix is what I am driving @

lordsneed
12-01-2011, 05:55 PM
I understand the basic concept of what I want it to do. My problem is programming the LED driver with it. I have never done hardware programming before, so I really am lost. I have read about people using bit pushing vs SPI (which people claim updates faster), however, I have never done either one of them before. Therefore, I really need more help with the actual coding than the general design concepts.

I have a 6x18 matrix to make a clock (3 LEDs wide for each digit) in bar style (7 segment style). I just need help with the actual coding using whichever method is the easiest to understand/deal/work with.

lordsneed
12-02-2011, 05:28 AM
I have actually found the solution to my problem. As I thought, it had nothing to do with hardware/current, etc but with the code. I disconnected everything and reconnected according to the layout on the following link:

http://www.pjrc.com/teensy/td_libs_Matrix.html

I also used the sample code to test. It all works perfectly. I hooked up just one matrix to test and it performed as it should. Now I will connect the other two LED drivers and the matrices and test with all three of them connected.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum