1

I have one RGB LED (common anode type), and while I can get every color to light up independently I am seeing some bizarre behavior when trying to combine colors. This is my first project involving LEDs, so I am trying to go slow and create a working python script that covers the basics so that I can reference it when working on the bigger build. I would be very grateful if someone could help shed some light on what I'm doing wrong.

The pattern seems to be that when multiple colors are called simultaneously only the first color of the set activates... but I have no idea why. What am I doing wrong here?

Details:

The components involved are:

The RGB LEDs are attached as follows:

And the code...

#!/usr/bin/env python

from gpiozero import RGBLED
from time import sleep

led = RGBLED(red="BOARD11", green="BOARD15", blue="BOARD13")

print("Common Anode - Full Red...")
led.color = (0, 1, 1)   # full red
sleep(2)

print("Common Anode - Full Green...")
led.color = (1, 0, 1)   # full green
sleep(2)

print("Common Anode - Full Blue...")
led.color = (1, 1, 0)   # full blue
sleep(2)

print("Common Anode - Magenta (R+B)")
led.color = (0, 1, 0)   # magenta
sleep(2)

print("Common Anode - Yellow (R+G)")
led.color = (0, 0, 1)   # yellow
sleep(2)

print("Common Anode - Cyan (G+B)")
led.color = (1, 0, 0)   # cyan
sleep(2)

print("Common Anode - White (R+G+B)")
led.color = (0, 0, 0)   # white
sleep(2)

led.close()

Results:

  • Full Red = Full Red (yay!)
  • Full Green = Full Green (yay!)
  • Full Blue = Full Blue (yay!)
  • Magenta (R+B) = Full Red <----- Not Right
  • Yellow (R+G) = Full Red <----- Not Right
  • Cyan (G+B) = Full Green <----- Not Right
  • White (R+B+G) = Full Red <----- Not Right
  • how much current is the LED designed to pull through each one? (based on LED and whatever built in resistor there is) It could be that the PI is not able to source enough current to light more then one at a time, therefor it only lights the one with the least resistance. Or at least one is getting more then its fair share of the current. You could try adding another resistor to the common anode to cut the total current down and see if that changes your results at all. – Chad G Sep 4 at 23:15
  • @Chad G - I am not sure about the LED design; the spec sheet isn't terribly helpful. I did buy a 5v/2.5A power supply for the Pi... seems like there ought to be enough current available to the Pi at least (?). Once we start talking about resistors I start to get out of my area (part of why I wanted the button with built-in resistors). I don't have any on hand... any suggestions on what I should try to source to test? – GrinningX Sep 4 at 23:27
  • The datasheet lists the LED as being 12V(Even though adafruit says 3-6) . But the 3.3V from the pi might not be enought to drive them when doing more then one at a time, or again, there ends up being a dominate one. I would probably suggest getting a bare LED and a couple resistors, Or really, I would get LED strip from amazon (way more fun and there are plenty of tutorials on them for the PI) – Chad G Sep 4 at 23:47
  • I found that if I modify the 2-color combinations to use just half brightness then it would work, so a lack of current seems likely. For anyone that hits this in the future, I actually found that every so often even at half value I would only get one LED (1 in 20 or so, I'd say), so something just under half value (perhaps on a per-LED basis) would probably be more reliable. No luck at all trying to drive 3 LEDs at once to make white though, at any value. – GrinningX Sep 5 at 14:31
2

Your Question is lacking detail (as is the reference) BUT the Pi GPIO is rated at 16mA max (they will actually provide more, but at reduced voltage - using more is at your own risk).

The link states "keep the LED current at around 20mA" - implying that they are intended to draw this much current.

The Pi GPIO bank is rated at 50mA max.

NOTE different LED colours have different voltages.

It is more than likely you are overloading the Pi GPIO.

Pi GPIO CAN drive small LED to reasonable brightness, provided a suitable series resistor is used but not bright LED.

Incidentally it may help if you actually followed the instructions and set active_high=False.

| improve this answer | |
  • I found that if I modify the 2-color combinations to use just half brightness then it would work, so a lack of current seems likely. For anyone that hits this in the future, I actually found that every so often even at half value I would only get one LED (1 in 20 or so, I'd say), so something just under half value (perhaps on a per-LED basis) would probably be more reliable. – GrinningX Sep 5 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.