Scrolling text on LED matrices using SPI and arduino Mega2560

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?

}

The smiley face was suppose to be 8 )

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.

eightx32display_progmem_eeprom.zip (7.35 KB)

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.

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.

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....

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?

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?

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?

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.

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......

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.

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....

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 ...

Thanks for clearing it up. Ya I'm going to assign ss0-ss3 like I said using 53,49, 48 and 47.

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.

Why not wirewrap it? So much easier, quicker - and if you have to redo the matrix connections, its lot easier!

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.

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.

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?