question about LED matrix's
BobbyJ
Posts: 22
I'm [noparse][[/noparse]going to be] using a 4x4 LED matrix to help fine turn and debug my current project. I looked at a·few examples for controlling multiple 7-segment LED displays and figured something like that would work for me to get the number of LEDs I need and save a bunch of I/O's at the same time. The wiring seems·simple enough·and I don't think I have any problem there. But the code is where I'm a bit confused.
This should help illustrate:
13---14---15---16----RB7
·|····· |····· |····· |
·9---10---11---12----RB6
·|····· |····· |······|
·5----6----7----8
RB5
·|····· |····· |····· |
·1----2----3----4
RB4
·|····· |····· |····· |
RB0·· RB1·· RB2·· RB3
The numbers by them self are the LED's and the RB(x)·are the I/O pins. The LED's get +5v·from RB0-RB3 and ground is RB4-RB7. Lets say I want to turn on LED 1. RB0·is set high and RB1-RB3·set low. RB4 is set low and RB5-RB7 are set high. Is this correct? LED 1 would get the +5v and ground it needs to light up, but LED's 5, 9, and 13 would get +5v on both leads. Wouldn't connecting 2 or more pins together like that when they are all set high be a bad thing? I had·a 'whoops'·the other day and·would like to keep my supply of SX's from getting any lower if possible. I've got the code writen incase it is correct and really want to see these suckers light up. But I'm a bit nervous about applying the power. Am I worrying for nothing?
P.S. Happy Whatever-You-Celebrate-This-Time-Of-Year to all
This should help illustrate:
13---14---15---16----RB7
·|····· |····· |····· |
·9---10---11---12----RB6
·|····· |····· |······|
·5----6----7----8
RB5
·|····· |····· |····· |
·1----2----3----4
RB4
·|····· |····· |····· |
RB0·· RB1·· RB2·· RB3
The numbers by them self are the LED's and the RB(x)·are the I/O pins. The LED's get +5v·from RB0-RB3 and ground is RB4-RB7. Lets say I want to turn on LED 1. RB0·is set high and RB1-RB3·set low. RB4 is set low and RB5-RB7 are set high. Is this correct? LED 1 would get the +5v and ground it needs to light up, but LED's 5, 9, and 13 would get +5v on both leads. Wouldn't connecting 2 or more pins together like that when they are all set high be a bad thing? I had·a 'whoops'·the other day and·would like to keep my supply of SX's from getting any lower if possible. I've got the code writen incase it is correct and really want to see these suckers light up. But I'm a bit nervous about applying the power. Am I worrying for nothing?
P.S. Happy Whatever-You-Celebrate-This-Time-Of-Year to all
Comments
Do you have a program that will create a schematic you can upload?
www.expresspcb.com is a free EASY to use PCB layout program that also has a schematic drawing program that is also EASY to use.
Multiplexing would take a little bit of work, but would give you discrete control. My January N&V column (which I just got in the mail yesterday) discusses LED multiplexing. Since the column is out, I will post the code and schematic here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/25/2004 3:09:22 PM GMT
The goal is·use the LED's to help show how much movement I'm getting from a mouse connected to an SX28. Right now I·am·only using·8 LED's to show movement on one axis at a time. In order to see the other axis I have to change the code and then reprogram the SX. At any given time only 1 LED is lit up. Each LED is·connected to it's own pin (RB.0 - RB.7) and each·has it's own 470 ohm resistor. I want to be able to expand this to see both axis at the same time, but I do not have enough availble I/O pins to directly connect 8 more LEDs.
What I·have is·have·16 LED's·setup to form a plus (+) sign, 8 left/right (x-axis)·and 8 up/down (y-axis).·4 LEDs will be used to show each direction.·There are two·varbiles that·are·used to decide which·LED needs to be lit up,·one for x-axis and one for y-axis and these are·updated approx. every·100ms. Each varible·is an 8-bit value that is being scaled down, but not·evenly. Right now, the·1st LED will light up when the varbile has a value·between 1-5, 2nd is 6-15, 3rd is 16-40, and 4th is·equal to or greater than 41.·Thanks to having a processor that is so darN fast, I have a bunch of loops that·eat up most of the 100ms between data packets doing nothing. The idea is that after·the varibles are updated with new movement data, instead of going through those loops and doing nothing but waisting time, the code will go into a loop that does the following:
turn·one LED on the X-axis on
wait a bit
turn of the LED
wait a bit
turn one·LED on the Y-axis on
wait a bit
turn off the LED
wait a bit
I'm not exactly sure how long it would 'wait a bit'·and I'm not sure if I'll actaully need it to 'wait a bit'. I·get too frustrated trying to figure out how many clock cycles instructions use, so I haven't done the math yet. I figure·I can do that later, or come up will an excuse not to do it at all.·The goal isn't to have the LED's light up as bright as they possibly can, or even as bright as the SX will allow. But I'm fairly certain that if I use up a lot, if not all, of the time that is currently being used in loops doing nothing, I should be able·get a desent refresh rate.
I hope that makes sense.
Your idea will work fine as long as you expect to turn on only one led at a time. That is, when you wish to show the next LED for 100 msec then first turn the previous one off before you turn the new one on.
Happy experimenting!
Peter
http://www.sxlist.com/techref/io/led/8x7s8pin.htm·is for 7 segment displays, it can easily be adapted to matrix display. Electrically, a 7 segment display is only a row of 8 LEDs with a common cathode. 8 rather than 7 because of the decimal point. This will allow you to control 56 LEDs with 9 IO pins (one full port and one pin)
Watch out for PCB Express... if you use thier program, you can never use another PCB House and you can not share the file or upgrade to a better program in the future. I personally have designed a very complex board with the version of that program that was current when I started, only to find that the new version wouldn't load the file and they would not accept an order from the old program. I'm still waiting (years later) for thier support to get back to me (yah right). There are lots of better, more standard free programs available that will put out files anyone can read or will allow you to print your own artwork for toner transfer, etc... See:
http://www.sxlist.com/techref/pcbcads.htm·for a good list.
If you can wrap your head around the wierd user interface, eagle is great. For windows users who want a program just as easy as the express PCB program see
http://b.urbani.free.fr/pagetci/tci.htm·which is in french, but a translation to english exists... I'm still trying to get ahold of the author gain permission to publish it. It's so simple you can figure it out without reading the language.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
You can save one SX I/O pin with the following scheme. It requires two extra transistors.
If you are out of I/O pins as was the case for me, you can control both with one I/O.
When rb.x is high, the NPN transistor is on powering one of the 7 segs, while the PNP transistor is off.
Conversly, when rb.x is low, the PNP is on, and the NPN is off.
Ken
New image.....It should go without saying a resistor is needed for each segment. My origianl drawing did not include one.
Post Edited (KenM) : 12/26/2004 7:47:09 PM GMT
Are you interfacing with a PS/2 mouse by any chance?
It occured to me a while back that an COTS optical mouse could be turned into an interesting encoder-replacement for accurately detecting movement.
Unfortunately, serial mice aren't made anymore, and the PS/2 protocol is a bit more complicated than serial.
I was going to try to write SX interface code for a PS/2 mouse at some point, but I know that it's involved enough that I haven't had the time.
It sure would be nice if I could find where someone had already done this... And published the code... wink, wink. nudge, nudge...
JamesC, I am interfaceing with a PS/2 mouse. I've only used it with a 3-button mouse with scroll wheel, but·everything seems to be working correctly and it should be fairly simple to get it work with a standard 2-button mouse, or even a 5-button mouse. With a little work it should even be good for hooking up a PS/2 keyboard to an SX, thats on my to-do list of things to try. Thanks to the holidays, all I'll be doing at work for the next few days is wasting electricity by keeping the lights on and trying to keep the chairs from floating away. I'll see about cleaning up the code a bit and making sure it's commented correctly and then post it in a new thread for anybody thats interested.
You might want to·consider using·a driver chip at this time, like the ULN2803. The -03 inverts, but you can fix that in code. Each output will handle 500 mA, so will easily handle 4 LEDs at once. The -03 also has a single pin to drive all outputs, thereby allowing a 'lamp test'. This is mostly used for powering relays, and has a·diode at each output for back EMF protection. Go here for a data sheet:
www.nelnick.com/datasheets/ULN2803-D.pdf
This is an open-collector situation. The 2803 supplies a path to ground when the input is positive, but floats otherwise. This shouldn't be a problem in inactive circuits, but you might want to place a 1k pullup on each output to avoid potential problems.
These are available at DigiKey.
Happy Holidays!
kenjj