BlinkStick and Raspberry Pi

Lead Image © iimages,

Blink Bling

Replace a simple LED with more powerful and flexible BlinkStick devices.

LEDs are great. Not only do they offer a simple way to add visual feedback and blinking goodness to your amazing Raspberry Pi projects, they are also ideal for learning electronics basics and mastering the art of GPIO programming. But, LEDs do have a few limitations. LED-based circuits are usually connected and controlled via Raspberry Pi's GPIO pins, which can be impractical for certain projects. Adding one or two LEDs to Raspberry Pi is relatively easy, but using a handful of LEDs in a project can prove rather difficult to wire, control, and troubleshoot – not to mention that the finished result may look rather messy.

Enter BlinkStick [1], a family of LED boards that connect to a USB port and can be easily programmed using your programming language of choice. Although BlinkStick products are more expensive than regular LEDs, they are more convenient to use, they can be deployed in seconds, they look good, and they are more flexible and easier to control. Additionally, both BlinkStick hardware and software are released under open source licenses. In other words, a BlinkStick board can be a perfect fit for your next Raspberry Pi project involving LEDs.

Meet the BlinkStick Family

Born as a single relatively simple LED device, BlinkStick has evolved into several distinct products. Each BlinkStick model has unique characteristics that make it suitable for specific projects and purposes. So, it's worth checking out the features of each BlinkStick board before you opt for a specific one for your next project. All BlinkStick models have one thing in common, though: They feature bright multi-colored RGB LEDs that can be controlled individually.

BlinkStick Nano is the most basic and the least expensive model, and it lives up to its name. As small as a thumbnail, this board features two LEDs on each side and plugs directly into a USB port. This model is perfect for projects where size and neat design matter.

If two LEDs are not enough for your needs, consider BlinkStick Square. Slightly larger than the Nano model, it boasts eight multi-color LEDs. Unlike Nano, Square cannot be plugged directly into a USB port. Instead, this model has a micro-USB port, and you can use a regular data micro-USB cable to connect Square to the Raspberry Pi. Better still, a 3D-printed enclosure is available for BlinkStick Square, which can give your final project a nice finishing touch. Keep in mind, though, that the enclosure must be purchased separately.

BlinkStick Strip is similar to Square, but it has eight LEDs arranged in a row. This design makes it suitable for projects where LEDs are used to represent measurable values. A plastic enclosure is also available for Strip.

Finally, the BlinkStick Flex features 32 LEDs on a flexible strip with a sticky bottom, so you can attach it to practically any surface. You can cut the strip to the desired length and number of LEDs. The Flex model is ideal for projects on a larger scale, like adding ambient lighting to your workplace.

Several other products are available on BlinkStick's website, but these four should be enough to get you started.

First Steps

All BlinkStick models are controlled using the dedicated BlinkStick Python package that can be installed using the Python PIP tool. If the latter is not already installed on Raspberry Pi, you can fix that using the following command:

sudo apt-get update && sudo apt-get install python-pip

Then, run the command below to install the blinkstick package:

sudo pip install blinkstick

By default, BlinkStick-related commands must be run with root privileges, but you can change that by issuing the sudo blinkstick --add-udev-rule command and rebooting the Raspberry Pi. Now, plug your BlinkStick board into one of the Raspberry Pi's USB ports, and you are all set.

The first thing to do, of course, is to check whether the BlinkStick board works properly. Open the terminal, run the blinkstick --info command, and it should detect the connected BlinkStick board and return its information (Figure 1).

Figure 1: Getting info about the connected BlinkStick board.

Using several simple commands, you can control BlinkStick directly from the terminal. The blinkstick --set-color=COLOR command, for example, sets the first LED on the board to the specified color. The actual COLOR value can be a named color (i.e., red, yellow, orange, etc.) or hexadecimal values (e.g., 008000, FF0000, FFFF00, etc.). The random value picks the color randomly, whereas the off value turns the LED off. By the way, the --set-color parameter is optional. So, the blinkstick --set-color=COLOR command can be shortened to blinkstick red.

In most cases, you'd want to control other LEDs on the board, too, and the index=INDEX parameter allows you to do just that. All LEDs on a BlinkStick board can be addressed by their index number, starting with 0. The command below sets the third LED on BlinkStick Square or Strip to yellow:

blinkstick yellow --index=2

The LEDs on BlinkStick boards are very bright indeed, and the --brightness=LIMIT parameter lets you control their intensity by specifying a limit between 0 and 100, for example:

blinkstick blue --index=5 --brightness=50

Besides turning LEDs on and off, you can also make them blink, pulse, and morph from one color to another using the --blink, --pulse, and --morph parameters, respectively. These parameters require color as their arguments, and both --blink and --pulse also need the --repeats=REPEATS option, which specifies the number of times the LED blinks or pulses:

blinkstick random --index=1 --blink --repeats 3
blinkstick orange --index=5 --pulse --repeats 5

The --morph option gradually changes from the current LED color to the specified one, and the --duration=DURATION parameter defines the duration of the morphing process in milliseconds:

blinkstick green --index=7
blinkstick orange --index=7 --morph --duration=5000

The preceding commands, for example, set the color of LED number 6 to green and morph it to orange during five seconds.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Welcome

    It is rumored that Thomas Edison tested thousands of filaments for an incandescent lamp before he produced the first commercially viable electric light bulb, and I imagine his is not a unique experience. Building mock-ups and working models exposes the weaknesses and strengths of a design, which prepares you to make a better version, then a better version, until you have found the right combination of materials, components, configuration, and cost.

  • Build audio and proximity devices with the Touch Board and electric paint

    An Arduino-compatible board combines cool audio features, 12 touch sensors, and electric paint to make the most excellent (and enjoyable) educational board yet.

  • IoT on Your Raspberry Pi

    The SunIOT project attaches a Grove base unit with a light sensor to a Raspberry Pi to measure various components of the light spectrum.

  • PHP on Raspberry Pi

    Getting started with PHP on Raspberry Pi is easy. We show how to build a simple PHP app to control an LED.

  • Programming the micro:bit with MicroPython

    The tiny micro:bit single-board computer from the BBC can be used both as an alternative and as a handy companion to the Raspberry Pi. Get started with this simple yet versatile machine.