Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SEARCH feature is gone? Scrolling on an 8 x 8 matrix

Status
Not open for further replies.
Very Funny, I almost forgot to laugh.
I am interested in finding out what different code does. Having issues with the software uart at times. I want to actually SEE what is happening within the code.
What really kills me is that no one can seem to understand what is actually happening or offer suggestions on direction. Only criticize my attempting to fully understand what and why a particular code statement will do.
I get the feeling that no one knows how to accomplish scrolling letters across an led matrix without the aid of shift registers, that's the impression I am getting.
 
Come on really I posted a arrow that move across to the right you could make it letters boxes lines LOL.
What little ghostman said get one thing to work like scanning a roll of leds. Then add to that.
Like Jon said, The code you posted is wrong cause like they said you came up with hardware first and then use code that's not for the hardware you using.
Code:
'code could be as simple as this '
Dim columns  as portB
Dim rows as  portC

while true
columns = %1000000
rows = %01111111
' delayms just a little here
columns = %1000000 'change these to make line letter add more 
rows = %01111111
' delayms just a little here
columns = %1000000
rows = %01111111
' delayms just a little here
columns = %1000000
rows = %01111111
' delayms just a little here
columns = %1000000
rows = %01111111
' delayms just a little here
columns = %1000000
rows = %01111111
' delayms just a little here
columns = %1000000
rows = %01111111'
'delayms just a little here
columns = %0100000
rows = %10111111
'Keep going till it goes across the leds then change to a
'letter
wend
wend
change the data for the rows and columns for a letter line box
then figure how to put the in a const to do the same thing then add more data to move the words like you want
 
Last edited:
I explained exactly what you need to do in post 17 and have amplified that several times.

What you should be saying is "I can't understand why no one will code this for me no matter how many stupid (substitute illogical and irrational if you want to be more socially acceptable) things I post and how much I whine."

That would be a true statement.

What you are attempting to do is not difficult. In fact, if you had actually mastered multiplexing for your turn signal project, this would be a trivial extension.

So I suggest again...read post 17 and Graham's tutorial on muxing a 4 digit 7 segment LED display. It's in Swordfish, and the principle is exactly the same.

Sorry you can't get anyone to do you homework for you. I already outlined my reasons. I think most people here don't mind helping with a project. I think they react angerly when you insult them and say nobody can do it since they won't do it for you.
 
I tried similar routine that Burt posted but getting two letters on one matrix? The code I posted with crappy video is doing same.
In my code I posted I am multiplexing as I slowed it down and each led just blinks for up to 10ms. I got arrows etc to scroll across but in the #17 post which I tried to replicate by scanning the cathodes but you lose part of the letters as you are loading each letter at a time. In my code that's what I was doing. If I insulted anyone Im sorry , not meant to offend but trying all suggestions. And just for the record, The code that Brad has that I posted a link to does not use a buffer for displaying the letters.
Using post # 17, you are not loading the second letter, only the one letter is scrolling across the matrix, at least that's the way I interpret it.
You load letter one then allow 1 or 2 blank spaces between letters then load second letter but letter one is still on the matrix. I think this is why Brad is only using 5 wide letters and why in his code he counts from 0 to 20 to display all 14 letters. I have been dissecting Brads code as it has a video that shows it works. Been dissecting and running each sub route to decipher what each tidbit does.
I have not asked for someone to code this, only direction. Have tried every suggestion including post #17 and 18.
The route I am headed now is building the data stream so the letters automatically stream across in one long data stream instead of each letter in it's own array. Then scan the cathodes as post 17 describes. All the letters are connected together as Brad has found works very well.
I will run Burts suggested code and maybe I am wrong??
 
....and maybe I am wrong??....

Well, I give you credit for getting exactly one thing right.

You might take a big sheet of paper and draw exactly what happens if you follow the logic I've outlined. Or you can follow the infinite number of monkeys approach.
 
Welcome to Chapter 1 of As The Stomach Turns: Teaching MrDEB How To Use a Matrix Display. I hope some of you will find this informative.

Since MrDEB has not blessed us with one of his usually stellar schematics, I think it's best if we assume nothing.

The illustration below show a bi-color 8x8 LED matrix from Sure Electronics that I happen to have. Ignore the red or green LEDs and you'll see what MrDEB is working with. This array has only 24 leads to illuminate the 128 LEDs inside (8x8x2). If every LED had two leads brought out, the package would be huge and impossibly complex. To make a manageable package, the LEDs are connected in a matrix. The anodes of all the LEDs in a given row (going across) are connected together and the cathodes are connected together in each column (up and down). There are actually two cathode connections in each column, one for the red and one for the green LEDs.

To illuminate any LED in the matrix, we can connect voltage across the appropriate row and column connections and the selected LED will light. But it's not possible to light up any arbitrary pattern of LEDs. Say we want to illuminate a diagonal line from corner to corner on the matrix. We'd have to connect every anode to illuminate an LED in very row, and all the cathodes because there's an illuminated LED in every column. What would the result be? Not what you want.

image.jpg



We'll have to employ some magic, and fool our eyes into thinking the the LEDs we want illuminated are always on. In this case, it's fortunate that our eyes have a relatively slow response time. In fact, anything flashing faster than 24 times a second is perceived by the eye to be a steady image. If this weren't the case, we would not have movies and TV.

The next illustration shows the basic arrangement of how an LED matrix can be connected to a microcontroller. The rows (anodes) are connected to 8 port pins on the microcontroller via current-limiting resistors. The columns (cathodes) are connected to 8 additional port pins. Life will be easier if an entire port is used for both.

image.jpg

Now, if we make every pin of port B high, and port C7 low, current will flow through each of the LEDs in the first column and they'll be illuminated. Notice each LED has a current limiting resistor in series with it.

image.jpg

Now, lets make port C6 low and port C7 high or open. The second column of LEDs illuminates. By setting port B as desired, and grounding exactly one port C pin at a time, we can display the desired pattern in any column. If we cycle fast enough, setting port B, grounding the port C pin for a period of time and repeating the process, the eye will see the pattern we desire. Let's go over those steps again:

image.jpg


1. Set Port B to show the desired LEDs in a column.
2. Make the Port C pin for only that column low and the others high, displaying the dots we want.
3. Wait some period of microseconds – longer will appear brighter, shorter will flicker less.
4. Make all of port C high.
5. Set Port B as needed for the next column.
6. Make The Port C pin for that column low.
7. Wait the desired period of time.
8. Do this again and again and again and again.... You get the picture.

One thing to note here...the time between updates is the time the microcontroller has to do things other than servicing the display. So where I said "wait" above probably doesn't mean a delay statement, which freezes the code. This display servicing should be done with an interrupt, so the code can go about its business except when it needs to service the display.

Easy, right? Well, not quite this easy. Remember those eight Port B pins that can each be supplying 20 mA to an LED? All of that current is trying to go to ground through one Port C pin. The maximum current any 18F-series pin can source or sink is 20-some mA. We've got a problem.

image.jpg

How can we handle potentially 160 mA with a single port pin? We could use an NPN transistor for each Port C pin; a ULN2803 (see some good information on the same part in a 7-section version at Wikipedia: ULN2003) is the easier way to handle this task. It has eight Darlington pairs that can each handle 200 mA, and the base resistors are built into the package. Best deal you can get for around 50 cents. Note – the part in the drawing below is mis-labelled. A shift register could also be used here to cut down on the number of port pins required, the that's something for another chapter of As a Stomach Turns... (with apologies to Carol Burnett)

image.jpg

Using the information here, a person should be able to get a flicker-free pattern on an LED matrix. Master and understand these basics while awaiting our next exciting chapter.
 
Last edited:
MrDEB, have you heard the saying Better to remain silent and be thought a fool than to speak and to remove all doubt? Or perhaps the more colloquial version attributed to President Lincoln, It’s better to keep your mouth shut and appear stupid than open it and remove all doubt? *

I'm not sure the relevance of the link you posted to the immediate topic at hand. But thank you very much for sharing it.

Clearly, the ULN2803 or another means of sinking a possible 160 mA is absolutely required. You could use the recommended chip, a shift register that can sink > 160 mA or individual NPN transistors but some sort of buffer must be used for two reasons:

1. A PIC18F-series chip can only sink a maximum of 20-25 mA on any port pin. If you are driving the LEDs with more than a few mA each, this limit will be exceeded.

2. it is true the PIC18Fs have a pretty remarkable sense of self preservation but will try its damnedest to sink as much current as it can. But if it will only sink 20 mA, the brightness of the LEDs in the column will vary depending on how many are illuminated. If a single LED in a column is on, it will be bright, if two are on, they'll be dimmer and if all eight in a column are on, they'll be really dim.

You really should be able to follow the simple explanation above.

Oh, and by the way, you said a ULN2802 "is not required but it helps." The '2802 has a base resistor set up to be driven by PMOS at 14-15 volts, so a '2802 isn't going to help at all in this circuit!

image.jpg
 
And back to As a Stomach Turns....

Let's look at drawing a character on the LED matrix. The picture below shows a letter A (remember, we're not here to criticize my ability to draw fonts).

image.jpg

The red numbers represent the value of each bit of the port. Any combination of port pins can be set high by setting the port equal to a number between 0 – 255. For example, the three LEDs shown in the left hand column can be set with:

PortB = 7

The first 3 bits (1 + 2 + 4) will be high, the rest of the pins low.

The eight values for columns to show the A above are

7, 60, 196, 60, 7, 0, 0, 0

So to display this letter, the pseudo code would be (assuming ports B and C are set to be outputs):

Code:
PortC = 0
While 1= 1

PortB = 7      'First column
PortC = 128
DelayMS(5)
PortC =0

PortB = 60     'Second column
PortC = 64
DelayMS(5)
PortC = 0

PortB = 196      'Third column
PortC = 32
DelayMS(5)
PortC =0

PortB = 60     'Fourth column
PortC = 16
DelayMS(5)
PortC = 0

PortB = 7      'Fifth column
PortC = 8
DelayMS(5)
PortC =0

PortB = 0     'Sixth column
PortC = 4
DelayMS(5)
PortC = 0

PortB = 0      'Seventh column
PortC = 2
DelayMS(5)
PortC =0

PortB = 0     'Eight column
PortC = 1
DelayMS(5)
PortC = 0

Wend

So, in short:
1. Set PortC low
2. Set PortB to the desired pattern
3. Set the appropriate bit of PortC to activate the column (exactly one bit high)
4. Leave the column illuminated for a period of time, drawing the entire 8 columns at faster than 20 Hz.
5. Repeat for the next column, and finally start over at the first column.

This A is five columns wide, so why did I scan all eight? Scanning all columns means each column is illuminated 1/8th of the time. If I had only scanned five columns for the A, each column would be illuminated 1/5 of the time. If the next character was, say a W spanning all eight columns, each column would be on only 1/8 of the time. Displaying the A followed by the W would result in a large brightness change if all of the columns aren't scanned all of the time.

Swordfish has a Portx.Bits(x) command to control individual port bits. You'll notice I did not use it here. The reason is simple. This command is very code-intensive. I can easily calculate the values I need to make the code run faster.

If you look back at the character code generator I posted, it's set up with bit 0 at the top and bit 7 at the bottom, which is the opposite of what I've shown here. That's probably the more conventional arrangement. I'm attempting to demonstrate fundamental principles in this short tutorial. If you understand the important concepts here, it will be easy to adapt to any arrangement.

Stay tuned for more...
 
This article is interesting reading. Have seen similar.
I have used the portb.bits(x) and yes it can get confusing but it is a valuable coding tool..
So far I give Jon a B+ for this informational article.
To add more confusion but helpful sometimes is portb(x),bits(y)
 
Today's episode of As a Stomach Turns....

From the illustrations above, you can see there are many connections to be made to get an 8x8 LED matrix in operation and the pin-out of the matrix isn't arranged in a logical order for connecting it. A quick test is a recommended step if you're wiring up one of these on a bread board or checking out a pcb.

The program below was written in Swordfish Basic. It lights up one LED at a time, from one side of the row to the other, moving row by row.

Code:
{
*****************************************************************************
* Name : Matrix Test.BAS *
* Author : Jon Chandler *
* Notice : Copyright (c) 2014 Creative Commons 3.0 sa-by-nc *
* : All Rights Reserved *
* Date : 3/12/2014 *
* Version : 1.0 *
* Notes : A quick test to verify connections and operation of an 8x8 *
* : LED matrix diplay. Rows are connected to PortB with series *
* : resistors, colums to Port C witn a ULN2803 or similar driver *
*****************************************************************************
}
'matrix tests
Device = 18f25k20
Clock = 20

Dim Column As Integer
Dim row As Integer

Dim i As Integer
Dim j As Integer
Dim speed As Integer

TRISB = %00000000
TRISC = %00000000

PORTB = 0
PORTC = 0
speed = 50

While 1 = 1

Column = 1
row = 1

For i = 0 To 7
PORTB = row

For j = 0 To 7
PORTC = Column
Column = Column << 1
DelayMS(speed)
Next
row = row << 1
PORTB = row
Column = 1
Next
Wend

This short program uses the shift operator to cycle a bit across the port, making each port pin high in turn. Exactly one dot should be illuminated at a time, following the pattern. Any dots that illuminate out of sequence, more than one dot illuminated at a time or missing dots indicate a connection problem or a defective array. If an entire row or column fails to illuminate, a connection problem is the most likely cause. Of the two arrays I've tried, the first had two columns tied together and the second has a dead row. You'll save yourself a lot of grief in program development if you make this check first.

Please note. This short program is not multiplexing the display. Only one dot is illuminated at a time by activating the appropriate row and column connections.

Below is a brief video on the matrix I tested...yes, there really is a matrix hidden among all those wires. Notice the right hand column does not illuminate. That's because I had a ULN2003 with 7 buffers and not a ULN2803. Also notice the third row from the top does not illuminate – this matrix is defective.

th_42596a7aacd4bbf3c707b9d0e98af8b6_zps0c2ad967.jpg
 
Last edited:
Thank you for the effort Jon, much work has gone in there. Excellent amount of information.
Mr Deb I think the frustration you feel is obvious, but your comment is totally unfair. The only thing you have not tried yet, is to change the way you work. Until you are able to alter your work pattern you are going to fail.
Everybody has there own way of doing things, but sometimes some methods will not work with all things. Electronics is not suited to the manic non methodical randomness, that can give results in other things.
For example. Madly running around a garden scattering seeds, may eventually give you a pleasing effect if you do it enough times.
Trying infinite amounts of code and making semi educated guesses at bits to change, will not get you a scrolling display. Throw as many variables and CONST CHARS at it as you wish, spatter as few or as many other SFB keywords in the mix as you please.
Even throw a packet of seeds at it if you want.
A scrolling display will not happen. You have got lucky a couple of times and made things work, but luck isnt very reliable.
So until you Alter your work method success I am afraid will elude you. That isnt Jons fault or Burts fault.
Both have supplied ample information, to suggest they are unable to create a scrolling display, when Jon in particular has written an outstanding write up on both the concept and implementation, is at the very least a poorly thought out response.
Fail to prepare then you have prepared to fail.

YOU need to stop ignoring the fact that your poor work practice, is what is making a weekend project a life long quest.

wipe the code from your computer, you may think its nearly there, or almost right. But the truth is you dont understand the code you have, therefore is it as much use to you as a rubber chicken in a gun fight.
Make 1 led appear at the edge, then turn it off and make another appear next to where the last one was.
BABY steps will get you there faster, than wildly running around with a blindfold on. Start with reading the concept, then move on to getting a single LED to move across one side to the other, this is the key. Get that Led moving fluidly from one side to the other, master that and then the rest will drop into place. 1 Led lets you see where its working and where you have messed up. When you break it all down a scrolling display is 1 led moving as you wish.
If you think about it a scrolling letter is just a group of single Leds. Master that first.
I could of course be wrong, maybe scrolling displays dont really exist, perhaps they cheat somehow. The more I start to think of it, your totally correct! scrolling displays havnt been invented yet! and Burts was a arrow so obviously that dosnt count, arrows are not letters therefore scrolling them is not the same thing. Shame on you burt for cheating like that ;)
 
Excellent comments all, LG. Alas, they will fall on deaf ears I fear, as has long been the case with any comment contrary to what MrDEB wants to hear.

It's summed up very well by a picture here.
 
Continuing the progression of As a Stomach Turns....

Getting the matrix array connected to a micro was the difficult part of this task. Getting a stationary letter to display is the next step of our journey. We're venturing into multiplexing now. We have to turn on groups of LEDs in succession to make a character appear on the display.

I didn't like my letter A, so lets work with a J for this step.

image.jpg

The first step is to determine the row data for each column. In the first column we want the top dot and the two dots next to the bottom. Adding the values of each port pin, 2 + 4 + 128 = 134. Continue this process for all eight columns. You can inspect the program below to see the values.

The process, as I outlined in an earlier episode, is simple:

1. Set PortC low to blank all columns.
2. Set PortB equal to the value for column 1.
3. Set the PortC bit corresponding to column 1 high.
4. Wait for a brief period of time.
5. Repeat the process for the remaining seven columns and loop back to the start.

Code:
'matrix tests - Letter J
Device = 18f25k20
Clock = 20

Dim Column As Integer
Dim row As Integer

Dim i As Integer
Dim j As Integer
Dim speed As Integer

TRISB = %00000000
TRISC = %00000000

PORTB = 0
PORTC = 0
speed = 1

While 1 = 1

PORTB = 134
Column = %10000000
PORTC = Column
DelayMS(speed)

PORTB = 129
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 129
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 129
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 254
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 128
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 128
Column = Column >> 1
PORTC = Column
DelayMS(speed)

PORTB = 0
Column = Column >> 1
PORTC = Column
DelayMS(speed)


Wend

That's pretty simple don't you think? The process isn't difficult. The program doesn't use interrupts for multiplexing but it's not necessary here where displaying the character is the only thing the program is doing.

(Click the picture to see the video on Photobucket)
th_IMG_2343_zpsd4f5fc40.jpg

What do you think? Looks pretty good, doesn't it? No. It looks like crap. If you watched MrDEB's recent video, it looks something like this. My apologies for subjecting you to this. The scan rate is too slow, so the eyeball sees the character being scanned, rather than perceiving it as a steady character.


(Click the picture to see the video on Photobucket)
th_IMG_2344_zps7c8024be.jpg

This is exactly the same code with the scan rate increased (by decreasing the amount of time each column is displayed). Here, the display looks absolutely stationary and uniform to the eye. There are a few artifacts from the camera but you can see the huge improvement in quality possible by understanding the process.

You might notice a difference in the shift command between this program and the last. The last program used the command:

Column = Column << 1

and this program uses

Column = Column >> 1

Can you spot the difference in the videos and explain why I changed this command?
 
Last edited:
I really can't help but mention that the above is exactly the procedure I outlined in post #22.
 
And, the conclusion of As a Stomach Turns: Teaching MrDEB How To Use Matrix Display.

We've learned how to connect a LED matrix display, including the need for some sort of buffer to sink current on the columns, how to test a display to make sure all the connections are correctly made, and finally, how to multiplex the display to show a symbol or character. The toughest part so far has been making all the necessary connections to use the display.

But a stationary letter is a long way from scrolling a message across a display, right? Not hardly! If you understand the fundamental principles discussed so far, the rest is simple. Let's start with the proof of the pudding first.

(Click image to view video)
th_IMG_2349_zps6b160864.jpg

Photos of illuminated LEDs are difficult, but you can see my J smoothly scrolling across the LED matrix. The character appears at the right, scrolls left and disappears smoothly off the display. Displaying a sentence is a simple matter of adding more characters to the data array.

The software shown here (in Swordfish Basic) is a brute force method – there's nothing elegant about it. The first step is to put the data to be displayed in a byte array. Each byte represents one column of the display, and we include 8 blank columns for leader and trailer. Since the point of this exercise is to teach MrDEB something and not to enable his mindless copy&paste(tm) programming method, the code is shown here in pictures. A PDF is attached so you can see the entire program.

image.jpg


Now, as was explained so long ago, all that is necessary is to display the first 8 columns (as we did for the stationary display) and slowly increment our way though the array. I'm simply counting a certain number of scan cycles (the ScrollSpeed variable) and advancing the index. We increment until the index is 8 less than the number of elements in the array (since we're displaying 8 columns after the index) and we start over. To display a longer message, increase the array size, load the column data into the array and have fun.

image.jpg


For the record, it took me about half an hour to go from stationary display to this scrolling display. This really isn't difficult once you understand the fundamental principles.
 

Attachments

  • matrix simple scroll.pdf
    30.3 KB · Views: 290
Last edited:
image.jpg


Notice the Creative Commons License MrDEB. NC means it's only released for non-commercial use, where commercial use would be any use of this code where you're compensated in any manner for its use. Either figure out the principles presented here and write your own code or contact me for licensing terms.

Creative Commons
 
Status
Not open for further replies.

Latest threads

Back
Top