How do I programtically  change power to bi-polar leds - Page 1
Forum section: electronics / general

author: RAPo
author_rank: Super Contributor
timestamp: August 22, 2024, 01:43:06 pm
content: I want to create an array of 64 bipolar 2-pin LEDs arranged in a de Bruijn cycle, lighting up 6 consecutive LEDs in one of the two colours.What I need is a method (by programming an Arduino or something like that) thatchanges a chosen subset of LEDs to the opposite colour, i.e. reversing the plus and minus applied to the LEDs.What is the best way to do this with minimal component count?To be explicit, the question is not about how to extend the number of GPIO pins,but is about the way to change the plus/minus voltages applied to a set of pins.

author: ajb
author_rank: Super Contributor
timestamp: August 22, 2024, 03:38:40 pm
content: Quote from: RAPo on August 22, 2024, 01:43:06 pmIt's not really possible to separate the two. There are many ways to solve the problem, but the best one will depend on how many IO pins you have available and what kind of control you want to have over the LEDs.Do you need to be able to turn individual LEDs off as well, or just select one of two colors? If you just need one color or the other, then you could use a single IO line per LED, route that directly to one side of the LED, and then through an inverting buffer to the other side of the LED. The state of the IO pin then selects the color. If you need to be able to turn LEDs off as well, then you can connect one side of the LEDs all together, drive that side with a pair of transistors (sufficient to handle the combined current of all of the LEDs), and then wire the other side of each LED to an independent IO line. Set each of those IO lines high for one color, low for the other color, or tristate for off, and then toggle the common side between high and low. That effectively multiplexes the LEDs by color, so all of the LEDs set to color A will be on, then all those set to color B, etc. You can use fewer IO lines by multiplexing somehow, but that's challenging with bipolar LEDs -- in any sort of matrix arrangement, there will be parasitic paths that will carry current through LEDs that should be off, and they might light up when you don't want them to. Modern LEDs are crazy efficient, and can visibly glow at surprisingly low votlage/current.Are you trying to control the brightness as well or just the color? Generally you wouldn't change the voltage to change the brightness -- if you want analog dimming, then it's better to control the current through the LEDs rather than the voltage. But it takes fewer components to do the dimming digitally, by controlling how much time each LED is on. Exactly how you accomplish that will again depend on how they are connected.

author: RAPo
author_rank: Super Contributor
timestamp: August 22, 2024, 04:21:12 pm
content: Thanks for your quick answer ajb.My situation is a bit more complex: each led can be one of three states: Off,Red,Yellow. Red color is +/- power, Yellow color is -/+ power.The program calculates a new state for each of the leads, and the LEDs will have to be powered off/on.A simplified example with 4 LEDs and two LEDS on goes as followsInitial led 1= off, led 2=Red, led 3 Yellow, led 4 =off.The program calculates the new state as display LED 1 and LED 3, all in color Red.So LED 1 has to have +/- power, LED 2 = off, LED 3=+/- power, LED 4 is off.Each of the possible states is possible, so in a next round LED 3 can be yellow (-/+ power) and LED 4 RED etc

author: AVGresponding
author_rank: Super Contributor
timestamp: August 22, 2024, 05:50:06 pm
content: Does this help?

author: fourfathom
author_rank: Super Contributor
timestamp: August 22, 2024, 06:21:42 pm
content: Quote from: AVGresponding on August 22, 2024, 05:50:06 pmAdd a current-setting series resistor,or probably two resistors if the red / yellow forward voltage drops are significantly different.edit: I forgot that was a two-lead LED. One resistor.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 22, 2024, 06:31:41 pm
content: I would treat it similar to driving a raw LCD display (sort of). Connect one side of all LEDs to a push-pull driver that's driven with a constant 50% duty cycle squarewave from the MCU. Then each LED connects to an IO pin via a resistor.1) If you want a LED off drive it in phase with the common.2) If you want a Red lit, drive it's IO pin low. (It'll be lit at 50% duty cycle)3) If you want it Yellow, drive it's IO pin high. (It'll be lit at 50% duty cycle with reversed polarity)You could also do dimming and color blending by varying the duty cycle of each IO pin.

author: ajb
author_rank: Super Contributor
timestamp: August 22, 2024, 07:00:29 pm
content: AVGresponding's circuit will work, but the gates are probably not necessary. Assuming these are modern low power indicator LEDs, you typically need 1mA or less to get adequate brightness, so if you have an MCU with 128 GPIOs available, you can just run one GPIO to each end of each LED and skip the gates altogether*. Likewise if you're using IO expanders, you'll need 128 pins either way, so the gates don't really offer any benefit here.You can get the same results using only 65 GPIO lines. I don't have any red/yellow bipolar LEDs in my library, but the basic idea is attached.If you have GPIO pins that can tristate (IE, you are connecting directly to an MCU), set the LED GPIO lines low for red, high for blue, or set them to inputs to turn an LED off, and then toggle theBlueand#Redline between high and low (you can tie them together in this case). The red LEDs will be on whenBlue/#Redare low, and the blue LEDs will be on when those lines are high. Toggle fast enough, and the eye won't notice the change, it will look like both are on at the same time.If you cannot tristate the GPIO lines (IE, if you're using shift registers or whatever to drive the LEDs), then you'll need to toggle between these states:- setBlue/#Redhigh and each LED GPIO high for blue, and low for off/red (blue LEDs will be on, all others off)- setBlue/#Redlow and each LED GPIO low for red, and low for off/blue (red LEDs will be on, all others off)Ideally you would change the states of all of the control lines at the same time, which is pretty easy with a chain of shift registers. If you aren't able to do that, then you might need to incorporate an 'off' state in between the red and blue to ensure that no LEDs light up during the transition.* Note that if you were to turn all 64 LEDs on at once the total current might exceed the maximum current rating for the MCU's power pins, in which case using gates would help. But for only 6 LEDs at a time that shouldn't be a concern with indicator LEDs run at reasonable current. If you're using IO expanders, then there isn't really a concern.

author: fourfathom
author_rank: Super Contributor
timestamp: August 22, 2024, 07:22:33 pm
content: Quote from: ajb on August 22, 2024, 07:00:29 pmIf that Blue/Red signal ever goes tristate (at power-up for example), those mosfets will probably be both biased on and draw huge current. I would use either the pull-up, or the pull-down -- not both.

author: ajb
author_rank: Super Contributor
timestamp: August 22, 2024, 08:45:03 pm
content: Quote from: fourfathom on August 22, 2024, 07:22:33 pmWhoops! I had originally drawn them as separate control lines, hence the separate pull up/down, forgot to delete one of them when I changed that, thanks!

author: AVGresponding
author_rank: Super Contributor
timestamp: August 23, 2024, 05:14:39 am
content: Quote from: fourfathom on August 22, 2024, 06:21:42 pmThe drawing was for conceptual purposes only. I also omitted the logic input pull-ups, and the power supply

author: ledtester
author_rank: Super Contributor
timestamp: August 23, 2024, 05:53:49 am
content: Are the LEDs going to arranged in a ring? If so I'd use those WS2812 smart RGB LEDs. You can get them already arranged in rings of various lengths:https://www.aliexpress.us/item/2251832604607665.htmlUnfortunately rings of 64 LEDs doesn't seem to be available but you can get 60 in a ring.Or get a strip:https://www.aliexpress.us/item/3256806037815487.htmlwhich you can divide up however you want to create whatever physical arrangement you want.Only requires one GPIO.

author: RAPo
author_rank: Super Contributor
timestamp: August 23, 2024, 06:10:45 am
content: Thanks for all these nice suggestions. I will check them out over the weekend. At the moment, I work with shift registers for the LEDs (just the 5mm one's)Yes, the LEDs are arranged in a ring (making a de Bruijn cycle). The program can ensure that only 6 less will ever light up.Indeed, going the WS2812 route would be the easiest, but there is something about seeing blinking lights the old way (and I have a thousand of them;-)).