|
META TOPICPARENT |
name="WebHome" |
RGB LEDs
Introduction |
| There are quite a few different types of breakout boards implementing RGB LEDs on the market which have to connected to the controller in different ways. Most of them just consist of 3 LEDs of the base colors implemented in a single package. Some of the breakout boards however have the necessary current limiting resistors already on board while for others they must be provided externally.
There is also a type of "intelligent" LED where the RGB values are provided in a serial data stream. |
|
< < |
 KY-009 SMD LED needing external resistors |
 LilyPad Tri Color LED |
|
> > |
 KY-009 SMD LED needing external resistors |
 Lily Pad Tri-Color LED |
|
|
 Standard 3 color LED with resistors on board |
 WS2812 "intelligent" LED |
For you information, here is the WS2812 data sheet
Programming the LEDs |
|
This cabling is of course only true for the first 3 devices (not the WS2812). To check the device we can temporarily connect these pins to Vcc (make sure the current limiting resistor is there, either in the breakout board or externally added by you) in which case we should see the corresponding color come up on the LED. Once connected to the gpio pins we can start programming. |
|
< < | Making a LED light up is one of the most simple programming exercises possible and therefore ideally suited to get us going with Python program. |
> > | Making a LED light up is one of the most simple programming exercises possible and therefore ideally suited to get us going with Python programming.
The following programs work for common cathode LEDs (KY-009 and Standard 3 color LED) only for which the GND pin is common. For Common Anode LEDs, which have a common Vcc like the the Lily Pad one you must pull the individual red, green, blue pins low to make the LED light up.
Three programs will be developed with increasing difficulty:
- rgbLED.py uses 3 bit binary numbers, where each bit corresponds to one of the three LEDs. A total number of 7 (+ all LEDs dark) can be displayed this way. First the pigpio library
is included and then the connections to the gpio pins defined and each of these pins set to OUTPUT. Then we switch the LEDs on, where the binary number 001 means that only green is on, 010 only red is on 100 only blue is on. A combination of bits like 011 or 110 mean a combination of green and red or red and blue respectivly.
- fullColors.py is a program that changes the light intensity from total dark to full color intensity for each of the 3 LEDs using Pulse Width Modulation (PWM).
- rgbColorIntensities.py finally combines both methods and allows the user to define an arbitrary color by entering rgb values through the command line.
You may download the file rgbLED.tar.gz containing all three programs. |
|
-- Uli Raich - 2018-01-30 |
|
META FILEATTACHMENT |
attachment="lilyPadTriColorLED.png" attr="" comment="" date="1517332550" name="lilyPadTriColorLED.png" path="lilyPadTriColorLED.png" size="156210" user="UliRaich" version="1" |
META FILEATTACHMENT |
attachment="ky-009.png" attr="" comment="" date="1517332550" name="ky-009.png" path="ky-009.png" size="148976" user="UliRaich" version="1" |
META FILEATTACHMENT |
attachment="2018-01-30-182614_520x384_scrot.png" attr="" comment="" date="1517333233" name="2018-01-30-182614_520x384_scrot.png" path="2018-01-30-182614_520x384_scrot.png" size="147250" user="UliRaich" version="1" |
|
|
> > |
META FILEATTACHMENT |
attachment="fullColors.py.txt" attr="" comment="" date="1517340249" name="fullColors.py.txt" path="fullColors.py.txt" size="711" user="UliRaich" version="1" |
META FILEATTACHMENT |
attachment="rgbColorIntensities.py.txt" attr="" comment="" date="1517340249" name="rgbColorIntensities.py.txt" path="rgbColorIntensities.py.txt" size="1016" user="UliRaich" version="1" |
META FILEATTACHMENT |
attachment="rgbLED.py.txt" attr="" comment="" date="1517340249" name="rgbLED.py.txt" path="rgbLED.py.txt" size="625" user="UliRaich" version="1" |
META FILEATTACHMENT |
attachment="rgbLED.tar.gz" attr="" comment="" date="1517340390" name="rgbLED.tar.gz" path="rgbLED.tar.gz" size="765" user="UliRaich" version="1" |
|