Go Down

Topic: Scrolling text on LED matrices using SPI and arduino Mega2560 (Read 9163 times) previous topic - next topic

Aaron_dyer

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?

}

Aaron_dyer


CrossRoads

#2
Nov 02, 2012, 06:47 am Last Edit: Nov 02, 2012, 06:53 am by CrossRoads Reason: 1
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
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Aaron_dyer

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.

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Aaron_dyer

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

Aaron_dyer

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?

Aaron_dyer

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?

Aaron_dyer

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?

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Aaron_dyer

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

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Aaron_dyer

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

CrossRoads

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 ...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Aaron_dyer

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

Go Up