This is the actual Scrolling Characters project that I initially developed and emulate in C#. You can find that project here and learn how I developed the core of the scrolling routines in C# to then extrapolate them to C++ for the Arduino Mega 2560.
The Max7219 LED Matrix is made of an 8 x 8 array of LEDs controlled by an MAX7219 Integrated Circuit as seen in Figure 1 below.
Figure 1: The MAX7219 Integrated Circuit. You can acquire an individual module or an array of 4 modules.
For this project I am using the SainSmart MAX7219 Dot Matrix Module 4-in-one which, as you can see in Figure 2 below, consist of four (4) individual MAX7219 assembled as one unit.
Figure 2: SainSmart MAX7219 4-in-1 Module.
On this project I will not be explaining the inner workings of the MAX7219 since there is plenty of literature in the internet, instead I will concentrate my efforts explaining how the Arduino Mega 2560 interacts with it to make characters scroll left, right, up and down. I have also developed a C# program acting as master and commander.
To handle the interactions between 2560 Mega and MAX7219 I am using the LedControl.h Library provided by Arduino. The LedControl.h takes a series of 1’s and 0’s arranged as the desired characters to accordingly power on and off the LEDs on the MAX7219 as you can see in Figure 3 below.
Figure 3: Displaying character A and its binary equivalent.
As observed above in order to display an “A” I have to send the 8 bytes to the left in an orderly timely fashion to create the visual effect of a character moving in different ways. It all depends how I choose to do the byte splash and the timing in between bytes.
So it is necessary to create a series of matrices, as the “A” above, representing the alphabet, numbers, and special characters then, by using the routines provided by LedControl.h, feed those matrices, according to a desired text, to the MAX7219 using a control program.
The MAX7219 provides three pins to facilitate the interaction:
Pin Name
Pin Description
DIN
Data In
CK
Clock
CS
Chip Select (Load)
The line of code below explains what pin in the Arduino is plugged to what pin in the MAX7219:
LedControl lcRow0 = LedControl(13, 12, 11, 4);
In the line above I declared pin 13 in the Arduino 2560 acting as DIN, pin 12 as CLK, and pin 11 as CS. The number 4 at the end states that I have a module with four (4) MAX7219 matrices arranged as one unit as seen in Figure 4 below:
Figure 4: MAX7219 Module outlined.
The following global variables will facilitate the handling of characters:
The character scrolling happens in memory to then displaying the characters in the module. In other words, what the module shows is only a reflection of what it’s in memory so as the content of memory changes so it does what the module shows.To handle that the following three variables are required:
Two arrays are also declared, one array holds what the user sent to the controller, and the second array is used to actually scroll the characters.
I have developed two routines to display and scroll the text, the first routine splash all characters at once to then scroll them until all characters disappear to the left. I have call this routine “Splash & Scroll.” Figure 5 below shows a graphic representation for this routine.
Figure 5: Splash & Scroll algorithm.
Observe how iteration 1 shows characters “ABC1” then iteration 2 shows “BC12” and so on and so forth until I reach iteration 6 where only character “3” is being displayed to then, start all over again. Then observe how the values on mIndexStart and mIndexEnd progress downwards as characters from Array Y are transferred to Array Z where the scrolling is actually happening.
See below the code for the “Splash & Scroll” algorithm and observe how a routine is called (Load_Message_v2(mYIndexStart, mYIndexEnd);) to move the next set of characters from Array Y to Array Z then, another routine is called (CheckBoundaries_v2()) to check the boundaries, and finally a call to a routine is issued to actually display of the characters (DisplayAllChars();)
It is important to remember that Arduino has a Main Loop where everything has to happen (unless Interrupts are used) so the routine above scrolls one character only and returns to the main loop where other tasks may be checked and processed. This is where Global variables become useful because of the need to preserve the memory variable values in between iterations.
The second routine starts with displaying the first character in cell 0 (zero) which is the first cell to the right then scrolling to the left. I call this method “Right Cell Start.” Check out Figure 6 below for a graphic representation of the algorithm.
Figure 6: Right Cell Start algorithm.
The code below shows algorithm number 2 also called “Right Cell Start.” Observe how, on its first iteration, Memory Array Z contains only the character “A”, then in iteration 2 it shows “AB” followed by “ABC”, and finally “ABC1” where the displaying slot is now full so in the next iteration it shows “BC12”and so on and so forth until the only character displayed is character “3” where it starts all over again.
The routines below do the actual splash of characters to the MAX7219 1 x 4 Module:
Below you can see a sample of what would be the GetChar() routine:
And finally below you can see a binary representation for a few of the ASCII characters.
For the character’s binary representation, I have an external file called Chars_Matrices.h that I “#include” when the programs starts.
So folks this is pretty much it for this project. I will be creating another project where I will be demoing bitwise shift which is an interesting way to scroll characters around so stay tuned for that. Don’t forget to check out the videos and let me know your thoughts in the comments section below. As always, thanks for checking out my electronics and programming projects.
Videos
Scrolling Characters using one (1) MAX7219 - Simple version.
Scrolling Characters using four (4) MAX7219 - Automated Process.