Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: Aaron_dyer on Nov 01, 2012, 08:49 pm

Title: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 01, 2012, 08:49 pm
Hey guys,

Ok, so I am trying to wire up 4  (8 x 8) LED matrices  = 32 x 8 ok.

I am off to a great start...I have the Datasheet for the Matrix so i know the Rows and columns..

and I'm basing it off of the MAX7219 (I have 4 of those - 1 for each matrix)

I'm wiring it up via this site:

http://www.arduino.cc/playground/Main/MAX72XXHardware#Wiring

and with the Mega 2560, using the SPI library, we would use these pin outs:

// SPI pin outs used for this on the Mega 2560 are: SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS)   

// We just need to use SCK - pin 52  MOSI - Pin 51 and SS - pin 53

// MOSI (Arduino) = Serial Data Out from Arduino (Asynchronous ~ Series) to Serial Data In (MAX7219)

// SCK (Arduino) = CLK (MAX7219)

// SS (Arduino) = Load (Synchronous ~ Parallel ) on MAX7219

// The 4 MAX7219s will be cascaded


I have seen a lot of code for scrolling text, but it seems like everyone uses the old LedControl or Matrix libraries..I just want to keep it simple and use the SPI library.


Can any coders out there give me a jumpstart help on the array to maybe just scroll "Arduino" across the matrices?

so for starters:


# include <SPI.h>

// SPI pin outs used for this on the Mega 2560 are: SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS)   

// We just need to use SCK - pin 52  MOSI - Pin 51 and SS - pin 53

// MOSI (Arduino) = Serial Data Out from Arduino (Asynchronous) to Serial Data In (MAX7219)

// SCK (Arduino) = CLK (MAX7219)

// SS (Arduino) = Load (Synchronous) on MAX7219

// The 4 MAX7219s will be cascaded


void setUp ()


{

    ...what could go here?

}

void loop ()

{
      ....what could go here?

}
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 01, 2012, 09:07 pm
The smiley face was suppose to be  8     )
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 06:47 am
Quote

seems like everyone uses the old LedControl or Matrix libraries

Not I!
See if you can wrap your head around this.

And youtube of it working. Needs a bezel still.
http://www.youtube.com/watch?v=hwYqgyMc5S4&feature=youtu.be
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 11:47 am
Crossroads, I've seen many of your posts before helping others with this concept. I actually downloaded your code once before but as I interpret it, it seems you have an UNO or a duelminove. I'm using a mega 2560 so I'm having to manipulate it correctly. But basically I have the max7219s correctly wired in....I just haven't uploaded code yet because the the mega is running many more things right now as well so I'm needing to integrate code together. I wanted to make sure any 8 x 32 code will work first. Is the YouTube video below your project?  Thanks again......the playground site I posted above on the max7219 is just like the block diagrams you drew before too.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 03:31 pm
328, 1284, 2560, its all SPI - just a matter of where the SCK, MOSI, and SS pins get connected. Very minor.
The picture and the youtube video are my current board -  an Arduino and 4 MAX7219's.
Any arduino will do - SPI.begin ( ) ; takes care of setting up the pins for you.
Mine aren't cascaded, so you need to adjust the setup tab and the display_update tab a little to reflect that.

I taped some "parchment paper" (cooking stuff, like waxed paper but sturdier) over the display and that seems to make the letters stand out more too. I'll do another video & repost it. I think I have it moving the letters along with either 50 or 75mS pause now, goes by  nice.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 05:00 pm
Ya in my previous posts, I realize the SPI pinouts just need to be changed since I am using the Mega 2560.. (No worries on that, I know the pinouts for SPI)

When I said cascaded, I just meant   Arduino -> data in Max7219   data out  ->  data in Max7219   data out  ->   

and so fourth like in this playground site:

http://www.arduino.cc/playground/Main/MAX72XXHardware#Wiring

I have an enclosure with the 8 x 32 display, a 40 x 2 LCD, a reset and an up down button for "volume control" I wanted to make it like a speaker type box with lots of lights / displays...I will take a video and show it to you soon....

all thats left is getting this SPI integration right....I am working on the PCB layout of the Max7219s right now....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 05:10 pm
Ok with your code...you have:

byte ss0 = 10; //MSB
byte ss1 = 9;
byte ss2 = 8;
byte ss3 = 7; // LSB


now on the mega2560   SS is pin 53     so what does the above mean?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 06:26 pm
Crossroads,

Man I would love to know what you mean by

byte ss0 = 10; //MSB
byte ss1 = 9;
byte ss2 = 8;
byte ss3 = 7; // LSB


I realize on the Uno board you have SS is pin 10  but pins 9, 8, and 7 aren't SPI pinouts...

I know the MSB and LSB = Most and least significant Bits.....

so heres a guess I'll throw out there....so for the Mega 2560  SS is pin 53.  so we know this:

SPI pin outs used for this on the Mega 2560 are: SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS)   



so if i were to wire it up and define the pinMode as:

ss0 = 53 // MSB     
ss1 = 49     
ss2 = 48   
ss3 = 47  // LSB          (because 52 -50) are the other SPI pinouts needed....

would that work?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 07:15 pm
One more thing Crossroads,

I watched your display on the youtube video...

The  "Howdy do boys? This ones for you"

where was that in your code?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 07:44 pm
This part in the pre-setup tab

byte ssOutput = 10;
byte ss0 = 7; //MSB -> easy to plug a header into Arduino
byte ss1 = 6;
byte ss2 = 5;
byte ss3 = 4; // LSB

You need the SS pin of the SPI group to be an output. I starte with 10-9-8-7, but then realized a header didn't fit across the gap, so I left 10 alone and moved the 4 non-cascaded SS pins to 4-5-6-7 instead.
Mine aren't cascaded - so connect the SS pin 53 to the first chip & go from there. SCK, MOSI, MISO are 13-12-11, but SPI library takes care of those so no pinMode is needed for them, only for the SS pin. The SS pin needs to be an output for the device to be SPI master, even if you are not using it for SPI.
You could use any 4 pins you wanted on the Mega, so 47-48-49-53 would be fine if you uncascade them.

The message - it's not in the code!  I enter it from the Serial monitor.
You can then enter SSS and it will save it to EEPROM along with the message size. After a power loss, or a reset, it checks for a saved message, if one exists it loads it from EEPROM into the displayArray and then starts displaying it. If  you then enter PPP it wipes the size stored in EEPROM and you enter a new message.

I think the one I posted will also let you add to the end of a saved message, and then saves the whole array to EEPROM again.
Or maybe not, and that was something I was fixing still.  No complicated math here, just playing with pointers into an array.

I am thinking now how to save the message as just the hex value of the character, and store that in EEPROM instead of the message itself, will let the message be 1021 characters long instead of just 170 characters.
If not storing in EEPROM, you can change arraySize to 1500  and store about 240 characters but the message is lost on power loss or reset.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 08:03 pm
so pretty much what you're saying is I can just leave it as :

byte ss0 = 53    and don't worry about   the 47, 48 and 49 as I mentioned before since its in SPI and my MAX7219s are cascaded?

its like this:

Arduino:

SS -- > (Pin 53 of Mega 2560) -----> Load of ALL MAX7219s (Pin 12) these would be in parallel

SCK -->(Pin 52 of Mega 2560) ----->    CLK of  ALL MAX7219s (Pin 13)  these would be in parallel

MOSI --> (Pin 51 of Mega 2560) -----> Serial Data Out going to the FIRST MAX7219 (Data In ~ Pin 1)   
                                                        Then from there Data out (Pin 24 of MAX7219) to the next MAX7219 Pin 1 (Data In)


and as Long as I connect the colums and rows up correctly to the matrices, the Code and the SPI will do the rest correct?

And also, you said you're typing in the serial monitor what to display on the matrices?


So I have it as

byte ss0 = 53; //MSB  <------- This is the SS output from Arduino Mega and with SPI library it should load the Max7219s


while you have it as:

byte ssOutput = 10;
byte ss0 = 7; //MSB -> easy to plug a header into Arduino
byte ss1 = 6;
byte ss2 = 5;
byte ss3 = 4; // LSB         

But yours aren't cascaded like mine......
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 08:11 pm
Exactly.
byte ss0 = 53    and don't worry about   the 47, 48 and 49 since its in SPI and the MAX7219s are cascaded

Yes, I type in the serial monitor what to display on the matrices.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 08:18 pm
So I think it just hit me what you've been trying to say...you don't want the Load or Pin SS to be in parallel coming from the arduino to each of the MAX7219s right? You wanted each MAX7219 to have its own individual LOAD pinout coming from arduino right?

thats why I should do the assignment of  the SS outs like this:

ss0 = 53 // MSB     
ss1 = 49     
ss2 = 48   
ss3 = 47  // LSB 

that just leaves the CLK or (SCK) from the arduino...that still needs to be parallel or (synchronous) right?


and you're saying you open the serial monitor and type in a message and it will display on the matrices?



(I just read your latest post) but I think I'm going to go along with what you have because you digitalWrite SS1-SS3 alot....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 08:43 pm
Yes, I have a unique SS/Load pin going to each device.  SCK and MOSI go to every part in parallel.  That seemed easier to code than running all the data thru all the devices every time to set up the MAX7219s and to update the display registers. You've got 84 IO pins on the Mega, so using 3 more SS pins is not likely to break the bank, is it?  Data on MOSI is serially clocked into the MAX7219s by SCK, so that is synchronous. All devices see the data going out, but only the device whose latch line is changing have the data latched into registers.

Yes, type on the serial monitor, as soon as you press Enter it shows up on the display.  enter everything as lower case letters. this punctuation is supported
. , : / " ?
If you enter + it stops the display, you can use < or > to manually sroll left & right 1 character.
If you are at the end and enter \ it takes one character off the end.  I think it might be of by 1 character tho. I'm still working on it.
Entering = after those restarts the scrolling.
I suppose I could make an Enter Text mode and then a Scroll mode, make it easier to see what is being entered and to back up to make corrections. One of these nights ...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 08:59 pm
Thanks for clearing it up. Ya I'm going to assign ss0-ss3 like I said using 53,49, 48 and 47.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 02, 2012, 09:22 pm
Kind of wish it wasn't Friday because I have this all at work so two days away from it.......oh well start back Monday.....good thing I can solder well too, this is going to be a rats nest of 28 gauge wire.......ill keep you posted crossroads and take pics n video soon too.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 02, 2012, 09:47 pm
Why not wirewrap it? So  much easier, quicker - and if you have to redo the matrix connections, its lot easier!
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 03, 2012, 12:55 am
MOSI and SCK in Parallel...Thats what I needed to make sure of...its this way in the schematics too....

I have 300 Ohm resistors for the I sets (Pin 18) on each of the MAX7219 ....The ss0 - ss3 Will be controlling each individual LOADs....

I placed the 100 nF and 10 uF caps to suppress any of the EMI in the circuit. I also have the code integrated and compiled / verified in 1.0.1 IDE.

just need to solder in each of the 16 pinouts wires from the MAX7219s to each of the Matrices.....

I'll keep you posted....

I noticed you said lower case letters must be used too....  < -------definitely remember that...

in your code though, you have all the HEX codes for each of the letters...is that to define them once they are input from the serial monitor? I thought it would scroll all of those in sequence when I first downloaded and read your code.



Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 03, 2012, 01:18 am
300 - that might be well on the low side. I always thought Table 11 was in k-ohm, as Figure 3 shows 9.5K.  But I can't find anywhere that it says Table 11 is k ohm.
I'd be careful with 300.

Those hex codes define how the LEDs are turned on/off to make each letter.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 03, 2012, 03:01 am
You may be right.....I usually used 330 for any common anode segment displays, but maybe I will go with at least 1K.....

And one more thing.....MOSI....this is the data pin coming from arduino to pin 1 ( data in) on the first max7219... But then pin 24 (data out) of the first chip would then interface pin 1 again of the next max7219 and so on through #4 . So that technically is asynchronous. the serial clk or SCK is the only Pinout that should be in parallel or synchronous......correct?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 03, 2012, 05:02 am
"MOSI....this is the data pin coming from arduino to pin 1 ( data in) on the first max7219... But then pin 24 (data out) of the first chip would then interface pin 1 again of the next max7219 and so on through #4 . "

You are using individual slave selects, yes? Then SCK & MOSI to go each device in parallel; nothing is daisychained out to in, out to in.

I am thinking your idea of synchronous vs asynchronous is different than  mine.

SPI is synchronous - data is accompanied by a clock source.
Asynchronous - no clock is provided, receiving device creates its own timing - such as RS232.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 12:43 am
So bottom line, SS or LOAD is interfaced to each individual chip coming from the assigned ss0-ss3.

SCK needs to in parallel with each chip sharing the same clock output from arduino.

Then the MOSI or data would go from arduino to pin 1 of chip.....pin 24 of chip goes to pin 1 of next chip and so on through number 4 max7219.

If I'm wrong here could you correct me.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 12:48 am
If data out from max7219 isn't interfaced to data in on the next max7219 sequence, are you sure MOSI Will work if its in parallel? All 4 chips sharing the data out from arduino like the SCK does? Look at the schematic in the playground link I posted in my pilot post of this topic.....that's the schematic I've been going by.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 12:59 am
Im confused now trying to understand why you would use MOSI (data) in parallel when the site and datasheet explains to cascade the MOSI.....could you post a quick schematic, or block diagram of what YOU have working please
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 04, 2012, 07:30 am
SCK, MOSI in parallel to all chips.
Seperate SS/Load to each chip.
It's just a chip and it can be wired any way the design calls for.
I went with 4 seperate load lines because I felt it made the coding easier for me.
In a situation with a more static display, having the data line daisychained might make more sense.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 12:46 pm
Ok, now I see....you have a point about manipulating a chip. I appreciate your patience. Let me bust out this wiring up job and ill send you pics and video. That looks like EAGLE CAD.....your schematic. Yes?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 04, 2012, 04:41 pm
Yes, eagle.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 06:08 pm
EAGLE is awesome. I sometimes use expressPCB and trying to learn more orCad and altium. I assume you're an engineer? I just graduated with my BSEET but have years of experience, but I just started tinkering with arduino this past year.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 04, 2012, 07:36 pm
I use expresspcb a lot for schematics just to post in the forum for discussion.
The lack of rubberbanding makes more complex designs harder to do.

Yes, I have BSEE from RPI.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 04, 2012, 07:43 pm
That's cool. I have an Associate's in computer and electronics engineering from ITT Tech. And just graduated from Devry with my bachelor's in electronic engineering. I'm starting my masters in project management in January.

Ya expressPCB is very simple. The PCB design portion of eagle I'm trying to learn more. The rats nesting of the traces always irritate me.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 05, 2012, 10:20 pm
Got 3 matrices wired up with 1 to go...heres the issue now.....the 3rd matrix blinks when I power up but then goes out...so I probed the row and its column and I'm measuring negative voltage....????? why is the Max7219 supplying negative voltage to the matrix rows?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 05, 2012, 10:29 pm
If anode is Low when Cathodes are  high (i.e. off)  for the next high anode, it can look like a negative voltage.
The LEDs for the low anode column are reverse biased and just turned off.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 05, 2012, 10:33 pm
I did up a sort of flowchart showing the program execution summary.
The code itself is 21 landscape pages long, but this lets you see the idea behind it.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 05, 2012, 10:49 pm
My code is way too long to post in this forum...could you give me your email possibly and I can send you a schematic capture and my code and see if you can see something I'm doing wrong .....making the LEDs have negative voltage,...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 05, 2012, 11:40 pm
I already explained that.
If you have the meter- on a cathode that is driven high, and the meter+ on an anode that is driven low, you will see a negative voltage. Perfectly normal.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 01:35 am
Well there's something up with either the code or the sequence I have the chips ....I dont understand why 2 of 3 matrices are full on .....all 64 LEDs on 2 and the next matrix is totally off.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 01:44 am
Guess I will wire up #4 and see if any scrolling takes place.....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 01:51 am
Sequence will not matter - the code works the same whether the MAX7219's are connected or not. I did a lot of debugging just using Serial.print statements.
Any chance the display is just flipped end for end?

You have the serial monitor opened and a few characters entered?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 03:32 am
So far I have 3 of 4 matrices wired up. I paid extra close attention to the columns and rows ......the first 2 are lit up totally....all 64 on the first 2. The third has none lit up and that's when I probed the anodes(+) and cathodes(-) in rows vs. Columns and saw the negative voltage. I opened the serial monitor and typed hello, but didn't see any effect......I still have the 4th to wire up.....ill update you on how that one reacts. Oh I don't doubt your code and debug, you had yours working........I think there maybe an issue with the integration of what I have and integrating yours in. I have a lot of lines that control an LCD , some buttons and LEDs too.....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 04:51 am
I guess I should mention this: so I have ss0 plugged into max7219 #1 which in the 32x8 display is the farthest on the left...then 2 goes to the second matrix from left and then 3 second from right and 4 farthest matrix to the right. MOSI all parallel, SCK all parallel, each ss (load) hooked up to individual chips......the matrices are wired up correctly too.....I just wanted to make that clear....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 05:01 am
Layout sounds correct & ss usage agree with the code.
May take some tweaking to make it all play nice.
Usually when they all light up its due to having had bad data sent in, or its in display test mode, or ...
I think setup is coded to have display test turn each one on/off briefly, 50mS or something.
I started with just putting a simple pattern in during setup to confirm that I could send data to each one correctly.
Small steps.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 07:18 pm
This is rediculous.....I have all 4 matrices wired up now 1 each to each MAX7219..

SCK all in parallel

MOSI all in parallel

SS to each Max7219 (Pinouts assigned)

I'm using 10K resistors for Iset



I would like to email you....I want to include my code in an .ino and see if you could take a minute and browse through it and see if theres anything wrong...



Also, I open the serial monitor and just type    hello

it makes everything reset......

IDK
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 07:23 pm
Put the code here as an attachment (pasting in text), can get some other eyes on it too.

How are you powering things? USB port? Any chance it is overloaded?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 07:29 pm
I emailed you the .ino file

I will have to shrink down the code to try and put it here..it exceeds the 9500 character limit...

To upload, I'm using the USB, but after upload, I have 2  (3.9 V ) lithium batteries = 7.8 V powering it all...

I'll try and shrink it down..

I have a lot of LED commands that would be irrelevant here...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 07:34 pm
I won't be able to look at that until 8:30pm.
Add it as an attachment here so others might look at it in the meantime.
(Click Additional Options below, browse to your file, and then post)
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 07:39 pm
Ok.....I must've missed that on the datasheet....

I'm going to open up the rats nest  (I have it all in an enclosure)

I'm going to replace the R's now...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 07:58 pm
Ok I have replaced the 10K's with 33 K's I had.....feel much better....the Matrices that would work were very bright......

so I closed it all back up....now the first matrix lights up totally..

the second matrix = Row 2 is only lit up...matrix 3 and 4 = nothing


I'll try and paste my code here....

I may have to shrink it down some....

I'm going to start trying to get the matrices working....

My LCD , LEDs, Buttons all work fine,....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 08:02 pm
Code: [Select]
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 08:26 pm
Attached is my schematic and how its wired up....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 08:32 pm
Do me a favor.

make these 2 changes
Code: [Select]

 // *******************Initialize the LCD**************//
 
/*  comment out the LCD and all the delays as a test
 
 lcd.begin(40, 2);
 lcd.setCursor(3,0);


Code: [Select]

   lcd.setCursor(0, 1);
   
   lcd.print("<-- Down Control        Clock:");

*/   end of commenting out LCD setup code
}
 
 
 void loop ()
 
 {
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 08:36 pm
Where are the 0.1uF and 1uF (or 10uF) caps on the VCC pin of each device?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 08:41 pm
Oh yes, I did include a 10 u F and 100 nF on the Vcc line for the first Max7219.....are you saying each chip would need this?
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 08:44 pm
I totally got rid of all the LEDs and LCD commands...I pretty much used your code and just changed ss0-ss3 to the pinouts for the Mega.....

When I open the serial monitor now....the 3rd and 4th matrices blink some but nothing accurate yet....

here is the code I'm using now....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 08:50 pm
Attached is a picture of my project is you're curious.....

Everything works how I would like it to except the matrices.....They are blinking erratically at times...or steady on....etc.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 09:13 pm
Enclosure looks nice!  Better than my PCB with Duemilanove cable-tied to it.

Yes, you need caps for each device. 0.1uF keeps high frequency noise,  10uF acts as local current buffer for the large currents being switched on/off.

Looks like you have slightly old code.  See if this helps

byte display_test = 0x0D;           This needs to be 0x0F,

byte displayArray[192] = { }; // 192 bytes

These need to be written with 0x07:
Code: [Select]

  // scan limit to all 7 columns
  digitalWrite (ss0, LOW);
  SPI.transfer (scan_limit);
  SPI.transfer (0x08);
  digitalWrite (ss0, HIGH);
  digitalWrite (ss1, LOW);
  SPI.transfer (scan_limit);
  SPI.transfer (0x08);
  digitalWrite (ss1, HIGH);
  digitalWrite (ss2, LOW);
  SPI.transfer (scan_limit);
  SPI.transfer (0x08);
  digitalWrite (ss2, HIGH);
  digitalWrite (ss3, LOW);
  SPI.transfer (scan_limit);
  SPI.transfer (0x08);
  digitalWrite (ss3, HIGH);


these need to be written with 0x01 for Normal mode (vs shutdown)
Code: [Select]

  // dispay test to normal
  digitalWrite (ss0, LOW);
  SPI.transfer (display_test);
  SPI.transfer (0x00);
  digitalWrite (ss0, HIGH);
  digitalWrite (ss1, LOW);
  SPI.transfer (display_test);
  SPI.transfer (0x00);
  digitalWrite (ss1, HIGH);
  digitalWrite (ss2, LOW);
  SPI.transfer (display_test);
  SPI.transfer (0x00);
  digitalWrite (ss2, HIGH);
  digitalWrite (ss3, LOW);
  SPI.transfer (display_test);
  SPI.transfer (0x00);
  digitalWrite (ss3, HIGH);


Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 09:53 pm
Why thank you...I made the enclosure with a Vernier Caliper, A dremmel and a file.......took a few days...I bought the 40 x 2 LCD for 2.75 $ and wanted to something with it right....

I then bought a mega and I wanted to have multiple things working on the enclosure....so I made the matrices as well.....

I updating the code now....

I did add the caps....now I can get some type of response from the 3rd and 4th matrix...at least I'm getting there now....

When I power up, its like the first whole matrix is lit, the 2nd row of the 2nd matrix is lit and then all of 3rd and 4th matrices are lit.....

When I open the serial monitor, the LCD resets and goes through the setup again......

getting there.....Arduino is so much fun.....debugging and all...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 06, 2012, 10:05 pm
"Arduino is so much fun.....debugging and all..."
I know what you mean - epsecially doing things like copying addresses wrong from the datasheet - took me two nights to figure that one out!
Or even better - I was saving stuff to EEPROM - totally overlooking the fact that there are only 1023 bytes, while the code  happily wrote to 1500 bytes & hosed the data I was putting there. Someone else spotted that for me.  Worked great while I was buffering in the 2048 bytes of SRAM even!

The other thing I did was to write 0's to all the digit registers before anything else, right after the pinMode commands, so when they then come out of shutdown mode they don't turn on by themselves.
Code: [Select]

  // clear the MAX7219 digit registers

  digitRegister = 0x01;  // digit0, up to 0x80 for digit7
  for (x = 0; x<8; x=x+1){ 
    digitalWrite (ss0, LOW);
    SPI.transfer (digitRegister);
    SPI.transfer(0);
    digitalWrite (ss0, HIGH);
    digitRegister = digitRegister+1;
  }
  // next digit
  digitRegister = 0x01;  // digit0, up to 0x80 for digit7
  for (x = 0; x<8; x=x+1){ 
    digitalWrite (ss1, LOW);
    SPI.transfer (digitRegister);
    SPI.transfer (0);
    digitalWrite (ss1, HIGH);
    digitRegister = digitRegister+1;
  }

  // next digit
  digitRegister = 0x01;  // digit0, up to 0x08 for digit7
  for (x = 0; x<8; x=x+1){ 
    digitalWrite (ss2, LOW);
    SPI.transfer (digitRegister);
    SPI.transfer(0);
    digitalWrite (ss2, HIGH);
    digitRegister = digitRegister+1;
  }

  // next digit
  digitRegister = 0x01;  // digit0, up to 0x08 for digit7
  for (x = 0; x<8; x=x+1){ 
    digitalWrite (ss3, LOW);
    SPI.transfer (digitRegister);
    SPI.transfer(0);
    digitalWrite (ss3, HIGH);
    digitRegister = digitRegister+1;
  }
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 06, 2012, 10:24 pm
I'm not 100 % sure where you would add this in.....so I took a guess....

attached is my entire code so far....

the schematic and picture is posted...I replaced resistors with 33 K's now instead of 10 K's....

I have an electrolytic 10 uF cap on each device and a .01 u F ceramic cap on each (I was hoping that could work)

disregard the email tonight.....

I'm going to take a video tonight of it working so far.....so you'll have a better image...

attached is the code so far....with a few updates you gave me....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 01:19 am
I have recorded a video of what I have so far.....

I was thinking I may need to do a better job with the caps......

I may resolder them in from each Vcc on the max7219s to its ground and not just on a Vcc / Gnd plane......that run parallel ya know on the PCB (Radio shack board)

anyways, heres the video..

http://www.youtube.com/watch?v=TxtDsnzoABg

I bought 10 more max7219s tonight as well...10  for 4.99 $ can't beat that......

If I can't get this to work, I may just go with the Uno / Duelminove and use an i2c LCD to conserve the I/Os but then redesign the enclosure as well....


anyhows....Still WIP but I'm trying
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 01:29 am
I noticed and commented in the similar post going on about the coupling caps......It was mentioned to use a 10 uF polarized cap and no less than a 0.1 uF ceramic cap for each device....I'll change up the caps tomorrow because I know I didn't use the correct ceramic caps.....I think I used 0.001 uF
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 01:35 am
Taken from the Playground site we are mentioning here...I have it in my posting about the scrolling on matrices.....


"By no means these 2 capacitors can be ommitted (Left out), as it might lead to sporadic or permanent malfunctions. These types of errors are really hard to track down. Both capacitors must be placed as near as possible to the V+ and the Gnd pins of the MAX72XX. "


I need to re place the caps closer.....and not just on Vcc and ground planes.....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 01:43 am
Now I'm getting conused again......

this is taken from the playground website:

"If you read the datasheet for the MAX72XX you know that the drivers can be cascaded by simply connecting the signal DOut from one chip to DIn on the next chip. The signals Clk and Load(/CS) have to be connected  in parallel to each MAX72XX. There is no strict limit as to how many drivers can be cascaded that way."

I don't have the Loads connected in parallel...they are set up from ss0-ss3 individually from the arduino I/Os  53, 49, 48 and 47......
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 07, 2012, 03:34 am
Move the clear digits to immediately after the SPI.begin();

This chunk of code at the end of setup will leave display test on = all LEDs on:

byte display_test = 0x0F;           // 0x00 = normal, 0x01 = display test mode all on full

Code: [Select]

  // dispay test to normal
  digitalWrite (ss0, LOW);
  SPI.transfer (display_test);
  SPI.transfer (0x01);
  digitalWrite (ss0, HIGH);

I would put in a brief delay, and then set this register to 0 to turn it off.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 04:24 am
is there anyway you could take the code I pasted before and update it with your updates and repost it.....I'm starting to lose track of everything...I'd appreciate it....


Also one thing I need to be certain of.....

imagine you have your 4 matrices  going from left to right with each having the max7219 under them.....

the first max7219 that needs to be interfaced from the arduino is farthest to the right then going from right to left correct? Or is it farthest to the left going to the right.....

I know I'm blowing up these forums...I just want to get this right....

Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 07, 2012, 05:31 am
#0 is on the left, #3 is on the right.
I'll see if I can fix the code up.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 07, 2012, 05:38 am
Try this.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 05:47 am
Thanks for clearing up the sequence layout.:you have been so helpful.....I'm a junior engineer with a good yr. Arduino time......just wanting this to be right....ill upload in the morning once I do the caps better....need to find some 104's
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 07, 2012, 05:59 am
Okay, will be watching.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 03:22 pm
ok heres the latest...

I placed all the caps  some 10 uF polarized electrolytic  and some 0.1 uF (104) ceramic caps   on each of the max7219s  Vcc line....

I uploaded the code you fixed up for me.....

before, the matrices would just stay on fully 3 of 4 that is.....

now.....they do go out...I'm sure its due to the register clear you mentioned....

However,

I open the serial monitor with the USB stil plugged into the mega 2560 and type hello...

theres nothing on the matrices....but when I press enter after typing hello, the LCD resets.....

I made sure the layout sequence of the matrices was correct right...and Ohmed for a good 30 minutes that all the paralleling is measuring continuity....


Is there anyway that we can manipulate the code (without changing any wiring) to just have it scroll a string?   ---> no serial monitor...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 07, 2012, 05:47 pm
Ok check out the forum titled "MAX7219 in daisy chain. How many decop capacitors I need" it should be fairly newly updated, and in there is what I did.....I did end up cascading them and its working for the most part but the scrolling isn't going across one matrix to the next, it just scrolls the same letter on each matrix individually...

and the letters are backwards....I tried to swap the wiring on just one matrix to see what that would do and it made it erattic...

Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 08, 2012, 03:48 pm
latest....not quite working how I would like, but again..........WIP

http://www.youtube.com/watch?v=HQPnPPoyabQ


I had made this sparkfun shield in the past......I want it to do this....

http://www.youtube.com/watch?v=CDBkg4vKbX0

I found how to do that from here:

http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix


but now messing with the max7219s is tricky...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 08, 2012, 03:51 pm
My bad..I posted the video and not the shield.....the video obviously was before the shield...

theres a pic attached of the shield now...
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 08, 2012, 04:59 pm
You've obviously got the MAX7219's working.
What you need a grasp of now is using arrays to send them data.
Here's the way I did it.
I have an array, called displayArray.
In this example it is 64 bytes,  displayArray[0] to  displayArray[63]. In my code, I made it 1022, so it can  be stored in EEPROM & saved during a power outage.
There is a pointer that keeps track of where the data will start that will be sent to the MAX7219s, called displayStart.
You load up displayArray by whatever means (preload it in the pre-setup byte array definition for example).
Then you use the displayStart pointer and copy the data to the MAX7219.

So if displayStart = 7, then the data from displayArray[7] would be copied into display0 register1, up to displayArray[14] going into  into display0 register8
next, display1 gets displayArray[15] to displayArray[22]
and so on for display2 and display3.
That data sits there for 100mS, then displayStart gets bumped to 8, and the process starts again.

(NOTE -the names below the diagram should have read display0, display1, display2, display3 - little copy & paste error)
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 08, 2012, 06:53 pm
I remember arrays in C++ class but I'm just not a great programmer..still amateur .....

I've attached my latest and somewhat greatest code.....I'm going to build up a protoboard matrix with my Uno...I'm surprised nobody has tried this with the mega 2560 like me....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 08, 2012, 07:01 pm
"I'm surprised nobody has tried this with the mega 2560 like me"
You're sending data out the SPI port to a MAX7219. Choice of microcontroller doing it makes no difference. Its the understanding of the manipulation of the data that makes it work. Uno, Fio, BT, Promini, Maga1280, Duemilanove, Deicamila, Leonardo, Bobuino, the hardware does not matter.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 08, 2012, 07:27 pm
you're right....but you use the serial monitor quite a bit......and arrays is dusty to me.....trying to get more skills on that
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 08, 2012, 07:35 pm
Yes, serial monitor is nice for sending debug statements to see what is going on, comment them out as things work and they are no longer needed.

Once you understand arrays and pointers into arrays and copying data from the array and putting it somewhere else, things will start gelling.
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: Aaron_dyer on Nov 08, 2012, 09:57 pm
I have a single 8 x 8 scrolling very nice now......And just a heads up...


with the 8 pins on each side of the matrix I thought pins 1-8 were swapped and pins 9-16 were swapped right...


No.....because I just wired up this single 8 x 8 how I have it in my enclosure.....did the same thing...letters are backwards.....

so I swapped the Column pins ONLY.....Like C0 - C7       C1 - C6           C2 - C5         C3 - C4   

and now its scrolling like a champ.....(just the one matrix I have with my Duemilanove here:)

pic attached


I'm going to try and consolidate more code and get my enclosure working fully...after I swap some column wires too.....
Title: Re: Scrolling text on LED matrices using SPI and arduino Mega2560
Post by: CrossRoads on Nov 08, 2012, 10:26 pm
Yes, need to "map out" the display being used.
I had to turn my 4 displays 90 degrees and re-wire them, (and then flipped the columns in the code anyway) to have the LED at Anode7, Cathode7 be the upper left, and Anode0, Cathode0 be the lower right.