Tag Archives: RGB LEDS

Blinkt! is Compatible with the Raspberry Pi

If you are interested in learning how to control RGB LEDs with the Raspberry Pi (RBPi) single board computer, Blinkt! provides a simple way to interface. Blinkt! is a strip of eight superbright RGB LED lights that you can connect to the RBPi without wires, so it is an easy way to start. Blinkt! Has a female connector that matches the male GPIO connector on the RBPi, and that allows the tiny LED board to sit atop the RBPi.

The RBPi can individually control each of the eight APA102 RGB LEDs on the Blinkt! board individually, so you can consider them as matrix of 1×8 pixels. The footprint of the board is tiny enough to allow it sit directly on top of the RBPi and the pair fits inside most of the Pi cases. Although the RBPi controls the eight LEDs with PWM, it does not interfere with the SBC’s PWM audio. Blinkt! comes fully assembled and is compatible with RBPi models 3, 2, B+, A+, Z, and ZW. Pimoroni, the manufacturers of Blinkt!, also provide a Python library for the users.

Combining Python programming and Blinkt! with the RBPi is a great way of understanding how RGB LEDs work and how a computer program controls their operation.

If you are using the RBPi3 for this project, it will already have the male GPIO on the board. However, the RBPiZ and RBPiZW may not have the connector, which means you may need to solder the connector to the board. You need to be careful when plugging the Blinkt! board onto the RBPi taking care to orient it in the right way. The Blinkt! board has rounded corners on one of its side, and this side should face the outside of the RBPi. Once you align the boards properly, push the Blinkt! board in and it should fit snugly on the RBPi.

To make the RBPi control the LEDs on the Blinkt!, it will need to have the right code. The best way to begin is to update the Operating System of the RBPi to the latest Raspbian. Once you have done this, and the RBPi is running, connect it up to the Internet and open the terminal on the RBPi screen.

Typing the code “curl https://get.pimoroni.com/blinkt | bash” without the quotes, should allow the RBPi to download the necessary Python libraries from the Pimoroni website. Now you can use the Python 3 IDLE code editor to use the library to write the Python program and control the LEDs.

While writing the Python program, you will need to begin by importing the Blinkt! library you had downloaded in the first step. Each LED is termed as a pixel so the parameter “set_pixel” allows you to address a specific LED, while “set_brightness” allows setting its brightness. The command “show” turns on the specific LED, and “clear” turns it off.

Even though the LEDs are numbered as 1 to 8 on the board, the program addresses them as 0 through 7. Therefore, the program can pick a light and tell it the color it needs to be, its brightness, and whether it should turn it on or off.

Controlling RGB LEDs via the Raspberry Pi

Digital gates are great for switching LEDs on or off. Micro-controllers are even better and so are single board computers. That is because they contain several gates to control the LEDs. To top it all, you can program single board computers such as the RBPi or Raspberry Pi to control several LEDs individually to run at different on/off cycles. Additionally, multiple color LEDs are available, such as RGB LEDs, with which you can generate any combination of the basic red, green and blue colors.

Although the GPIO pins of the RBPi can switch on an LED, the pins cannot supply beyond their limit. Therefore, when driving LEDs from the GPIO pins, a current limiting resistor is necessary in series with the LED, to prevent the IO pin from being damaged. The resistance value will depend on how much current the IO pin can source or sink, and the supply voltage of the RBPi or LED.

The RBPi has a 40-pin GPIO header among which, you can control several pins through software. The most common use of external circuits and LEDs with GPIO pins is to indicate status visually. For example, you may be controlling a remote circuit with software, and an LED nearby can indicate its status. The LED lights up to indicate the remote circuit is powered.

It is a good thing that human eyes have something called the persistence of vision. When we see something, its image persists in our eyes for a brief time. Therefore, we can see flashing lights only when they are flashing relatively slowly. Beyond a certain speed, our eyes cannot make out the individual flashes and the flashing light looks as if it is steadily lit. Using a technique called PWM or Pulse-Width Modulation, and controlling the on time of a GPIO pin through software, we can make an RBPi drive an LED such that it looks as if the LED is breathing. Doing the same with an RGB LED, the RBPi can cycle the lights to produce any color in the rainbow.

You can build a simple RGB LED board with a single bright RGB LED, three current limiting resisters and a four-pin connector on a prototype PCB. RGB LEDs have four pins and come in two configurations, common cathode and common anode. In the common cathode configuration, the package combines the cathodes of all the three LEDs into a single pin with the anodes individually available. For the common anode configuration, all the three anodes are combined into one pin, while the cathodes are individually accessible.

To drive an RGB LED you will need to connect its individual anodes or cathodes to three GPIO pins through current limiting resistors. If you use a common anode RGB LED, you will have to connect its common anode to a supply voltage. For a common cathode RGB LED, you will need to ground its common cathode. Now, you can switch on an individual LED of the combination by switching on the corresponding IO pin. See this tutorial for writing simple Python scripts for controlling the LEDs via the RBPi.