NeoPixels Strip on Raspberry Pi Zero

Looking into my desk’s drawer I found the remainder of an Adafruit NeoPixel strip I used in another project. And an unused, last years Raspberry Pi Zero. Does that work together? Well, yes, it does! At least after fiddling a bit with hard- and software and circumventing some common traps.

Searching the web I found a tutorial for steering a NeoPixel strip with a first generation Raspberry Pi. Technically it should work with an exemplary of a more recent version, but it did not initially.
Here is the description of how it all worked out in the end:

Hardware

Raspberry Pi Zero with up-to-date Raspbian Jessie Pixel
Mini USB WiFi Adapter (if the brand new Raspberry Pi Zero W is not used)
Raspberry Pi Zero adapter cables + power supply
Adafruit NeoPixel strip
1000 μF capacitor
330 Ω resistor
1N4001 diode
5 V breadboard power supply
breadbord, cables

Connections

  • 5V power supply GND : 1000 μF capacitor (short leg)
  • 5V power supply 5V : 1000 μF capacitor
  • 5V power supply GND : NeoPixel strip GND
  • 5V power supply 5V : NeoPixel strip 5V via 1N4001 diode (side with stripe goes to 5V input of the strip)
  • 5V power supply GND : Raspberry Pi Zero GND (physical pin 6)
  • Raspberry Pi Zero (physical pin 12) : NeoPixel strip data line via 330 Ω resistor

The available pins of the Raspberry Pi Zero are listed here. GPIO #1 correlates to physical pin 12 which is BCM #18. The latter is used in the Python software.

Don’t!

It is not recommended to use the 5V output of the Raspberry Pi Zero directly to power the NeoPixel strip. The pixels might draw too much current and might therefore damage the pin. It would have been way too convenient…so: an additional 5V power supply is strongly recommended.

Software

Running Headless: Setting up WiFi

To run the Raspberry Pi Zero headless (without display), set up the WiFi connection. For this step an HDMI display and a keyboard is required. Open the file

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Put the network configuration at the end of the file:

network={
ssid="WiFi network name"
psk="password"
}

Use raspi-config to allow SSH connections and to adjust the Pi’s hostname, the password, the time settings etc. .

SSH to Zero

When attaching the Mini USB WiFi Adapter instead of the keyboard and rebooting the Raspberry Pi Zero the desired WiFi network is used and it is possible to SSH to the Pi Zero. To find the IP adress in the local network check which devices are logged into the network at your routers access point. Or kindly ask your network admin to check. 😉

GPIO Checks

To see the available GPIO pins on the Raspberry Pi Zero run

gpio readall

NeoPixel Python Library

To set up the Python library for driving NeoPixels on a Raspberry follow this tutorial. Jeremy Garff’s Python library for NeoPixels is working like a charm.

Disabling Audio

To be able to use the PWM pins as data pins for the NeoPixel strip I disabled audio by commenting the line

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on  # disable audio for PWM pin usage

in the file /boot/config.txt.

Whether audio is disabled can be checked using

aplay -l

. If audio is disabled properly the result is an error message („aplay: device_list:268: no soundcards found…“).

Examples

Once the NeoPixel library is set up and the hardware is connected properly run strandtest.py or any other example code from the rpi_ws281x/python/examples section.

Result

That’s it! The NeoPixel strip finally can be driven by a Raspberry Pi Zero.

neopixeltest

While this example is working I definitively have a new project in mind…

Links

https://learn.adafruit.com/neopixels-on-raspberry-pi/overview

https://github.com/jgarff/rpi_ws281x

blinking bike helmet

A bike helmet could also light signal left and right on the push of a button. In the dark visibility is improved. As more and more car drivers don’t use their blinkers when changing directions it is also a nice statement.

components used
Adafruit Gemma
4 Neopixel
conductive thread, needle for sewing
small LiPo
two mini switches
hook-and-loop fastener
fabric
for testing: alligator clips

make it happen
Sew the components on fabric as shown on the pictures. Alternatively test everything using the alligator clips before sewing.

blinkinghelmet_circuitblinkinghelmet_blink

Important: the ‚data‘ thread of the neopixels should not continue below the pixels.

To place this on a helmet hook-and-loop fastener may be the right choice.

the source code
Load this program on the Adafruit Gemma. When the LiPo is powering the microcontroller push the switches to see either the left or the right LEDs blinking.

leftright.ino

The source code is based on the works of Leah Buechley, 2008.

how it works

When one of the switches is pressed the two pixels beside blink 10 times (adjustable in the source code).

blinkinghelmet_blink2

Please keep in mind that such an add on is never a replacement for proper lighting of the bike or showing your directions using your hands!

The Gemma and the Neopixels are also available in starter kits.

Of course there is no guarantee this description is free of bugs!

enlightened bag

Why not „enlighten“ a bag when opening it? This comes in useful especially in the dark.

components used
Adafruit Gemma
4 Neopixel
conductive thread, needle for sewing
small LiPo
soldering kit, small plate, cables
bag with metal zipper
for testing: alligator clips

making it happen

Sew the components in a bag as shown on the pictures. Alternatively test everything using the alligator clips before sewing.

enlightenedbag

enlightenedbag_inside

bag_plate

Realize the zipper switch to turn on the Gemma MicroController when the bag is open. A small plate with soldered cables is used to make the connection only when the zipper is open (=switched). Ensure that there is no connection on the plate for the bridged cable! Transparent nail polish helps to keep the knots from undoing. Needs several hours to dry!

the source code

Load this program on the Adafruit Gemma.

enlightenedbag.ino

how it works

When the zipper switch is used the microcontroller is powered on and turns on the LEDs one by one.

The Gemma and the Neopixels are also available in starter kits.

Of course there is no guarantee this description is free of bugs!

garden watering system

Since I have a garden regular watering is essential. But this can easily be automated with a micro controller. Here is a short description how the system is realized.

components used

Arduino Uno (or replacement)
12 V magnet valve
pressure sprayer, 5 l
flexible hoses, matching adapters
PIR sensor
IR receiver
TO 220 MOSFET
TIP 120 transistor
(red) LED
1 kOhm resistor
12 V power supply
old (plastic) box
wooden lath, screws
soldering kit, small plate, cables

making it happen

Bring the components together as briefly depicted below.

wetcat_circuit_wateringsystem_inside

wateringsystem_

The most time consuming is to find the proper hoses and adapters so that no water is leaking and the pressure lasts.

For the water output simple bend the end of a hose and prepare some holes with a hot needle.

the source code

Prepare this program for upload on the Arduino.

wetcat.ino

Adapt the code for your preferred IR remote control. It is possible to find out which codes they are with this example from an Arduino IR library.

how the system works
The red LED blinks several times when the system is powered on. The red LED is lighted when the water is running. The water runs when either the PIR sensor is activated for 5 s or as long as the matching remote control button was pressed.

The beautiful side effect of this watering system is that the neighbour cats suddenly decide to find another loo.

Of course there is no guarantee this description is free of bugs!