It's certianly possible - there's no real trick to it all - the hard part is the physical wiring.edyb wrote: Am I doing this all wrong? Is there a chip that I should be using to multiply the number of unique elements I can control with the GPIO pins?
Help please! Thanks!
You can do it with 2 resistors and 10 GPIO pins. Your program will need to work out the sequence to turn on each LED in turn based on the number each digit is to display. The down-side of this is that the program has to run constantly - stop the program (or make the program do something else!) and the display stops, or flickers.edyb wrote:A similar related problem which I thought I'd post is my desire to control a 7-element LED array. This is the product:
http://www.rohm.com/products/opto_devic ... bp-602ma2/
It is ROHM LBP-602MA2, which has 2 numeric digits.
There is a common ground for each digit on pin 13 or 14, and the rest of the pins are to control which LED gets turned on and off. I wanted to hook up to the RaspPi and create a program which turns them on in the right order to display numbers.
It says they are 20mA or 25mA current forward to I wonder what resistors I need. I assume I would have to put a resistor in series with each and every LED of the element, I don't think they are built-in. What rating do you think is good for this based on spec sheet?
Controlling the 2-digit display would use up all my GPIO practically, even if just using 14 LED I would have to buy 14 resistors and use 14 GPIO to control them.
Any thoughts on the resistors I should be using and if I have to use one for each LED in this numeric display? I also am thinking maybe a way to save on GPIO outputs I need by using a chip driver that will accept a binary code and convert it to the appropriate LED-light-on combination to just turn on the display to the correct number based on what the binary code from RasPi is provided. Then I can use 8 GPIO... 4 for each digit to allow up to 16 possible "numbers" (only need 0...9 digits and maybe decimal point) that will be enough to run the display.
In the simplest case, you can do it without transistors.edyb wrote:I've been looking at a few posts on Youtube about multiplexing and I thought maybe it would be possible to do so by using some transistors and flicking the LED's on really quickly in software to simulate the digital display. That works if you have the individual LEDs and can arrange them either in a matrix or to look like a 7-element LED numeric display.
However, if I used an LED numeric display already made (like the ROHM LBP-602MA2) it has all of the 8 LED's per number (7 for number and 1 decimal point) all connected to a common ground within the package. So I can't really "index" a particular LED in this package by using a matrix layout.
On the other hand, if I construct my own LED display an keep the grounds separate, I could theoretically light up any one of the group of 8 LED's using a 3x3 matrix (with one to spare). If I connect up 16 LED's for a 2-digit display then I have 16 LED's which I can index individually using a 4x4 array perfectly. Therefore I would require 8 GPIO pins total, and 4 PNP and 4 NPN transistors.
My program would know the position of each LED element in the display and turn on/off the appropriate ones based on the number one wishes to display. This would just be a translation table that knows for each number at each digit which LED's should be lit up as it maps to the 4x4 array, so my function could be made as simple as "displaynumber(var num)" and it would figure out what LED's to cycle through to display the number "num" on the display.
As long as it switches fast enough it should be able to do this without noticable flicker.
However, I am not sure based on the current part I have (with common ground) if it is possible to do this. Unless I can still create a 4x4 matrix and wire it up in a way where each node (16 in all) somehow links up to either feed current to or switch each of the LED inputs for the digital display.
Yes.edyb wrote:Thank you for the suggestions.
So I think I am understanding that if I use another GPIO pin instead of ground for the voltage "sink" on the ground side of my LED display, then if I set it to zero it acts as a ground? And if I set to 1 it is the same voltage as the GPIO's driving the LED display so no current flows and therefore that display is off?
You're limited to about 15mA per pin on the Pi - so really you don't want to have more than 1 LED lit at a time, so having one resistor is a safeguard in a way, as having one on each LED would let you light all the LEDs then they're all sinking into the GPIO pinedyb wrote: In that case using one resistor between the GPIO "sinks" and display should be enough (2 resistors) and I just have to make sure I cycle my program to turn off the GPIO properly not to turn on more than 1 LED at a time to avoid passing too much voltage through to the GPIO "sink"? Otherwise as better protection maybe I should buy a resistor for each LED and put it just before each LED just in case. Resistors are cheap anyways.
I guess by wiring up in parallel then I just cycle between my two GPIO "sinks" to switch between each of my LED 7-segment displays.
I am just not sure how much current comes out of a GPIO usually, is it 3.3V considered the "1" state and 0 V considered the "0" state (which is a grounding source)? No problems with the RasPi doing this?
That's exactly it. Just make sure you stick to the limits - keep just one LED lit at a time.edyb wrote: If that is the case, I could theoretically use the GPIO pins themselves to build up my MATRIX because I could connect say 4 GPIO horizontally and 4 GPIO vertically in a matrix to drive a 4x4 LED matrix. Then the default state of the horizontal rows can be OFF or "0" and default state of the vertical columns can be all "1". The LED will be polarized only to flow from horizontal to vertical with a resistor for each (or I can use only 4 resistors if I am cycling one LED at a time anyways).
Then I can cycle the state of a horizontal to "1" to drive the row of LED, but select which one of the LED in that row is lit by choosing a state of "0" for the GPIO that is acting as the sink in the verticals. This is in effect the same idea as using the transistors, but instead we are choosing to ground.
The biggest issue on the Pi is going to be the software - you will need to drive that loop to drive the LEDs constantly - stop the program and the LEDs will stop being displayed.edyb wrote: Any thoughts about this? That sounds like it should be pretty easy then, and we can drive 16 LED in a 4x4 matrix by cycling on/off just using 8 GPIO (4 driving the horizontals, 4 driving verticals) with nothing more than 4 resistors either placed at the start of each horizontal row or vertical column to limit current based on the LED that is being lit up.
I don't have the parts yet to try this, but planning on picking up some stuff from the electronics store soon (breadboard and a package of resistors). I have an old IDE 40-pin hard-drive ribbon cable which fits the GPIO header pins just fine and I can modify that to link up to the breadboard and have easier access to my GPIO. My 40-pin has all 40 pins accessible (it isn't the one that has a missing or blocked pin to ensure correct connection orientation)... so I can just chop off the extra or have it hanging off the end of the RasPi.
What is the other end of the LED connected to?edyb wrote:I am having some trouble with the Python program controlling LEDs... It seems to be working backwards.
My program is supposed to turn on each LED high in a row of 8 LED (each on a different GPIO) and the turn on sequence has a sleep delay of half second between each turn on... So I should she each LED turn on until my whole row is lit up.
Then when all of them are HIGH, I have a loop which shuts them all off with NO delay, so should turn off all almost same time.
What happens is the REVERSE.
It's as if HIGH and LOW are reversed. All my lights are on, then when I am turning them on instead it is turning them off 1 by 1.
Is this something with my wiring? Is GPIO by default 3.3v or 0? Isn't high supposed to be 3.3 and low is 0v so since connected to GND pin 6 should be LED off?
Users browsing this forum: No registered users and 3 guests