I´ve decided to add another layer of awesomeness to my Pimoroni Scroll pHAT HD by adding some fancy RGB LEDs to make it even more blinky.
The setup presented here basically consists of three parts:
- A Raspberry Pi Zero
- One Pimoroni Scroll pHAT HD white pixel display
- Thirteen RGB LEDs based on the WS2812B LED controller
I already had an assembled Scroll pHAT lying around, so I´ll leave this step out (it´s basically just soldering a pin socket onto it).
The WS2812B LED´s are pretty straight-forward to handle.
They provide 6 pins:
- 2 x 5V
- 2 x GND
- Din (data in)
- Dout (data out)
You just have to solder them in a row (5V to 5V, GND to GND and Dout to Din) to make them work.
Adafruit provides libraries for addressing WS2812B LEDs because they sell NeoPixels, which are also compatible with this controller. That means we can rely on quality Adafruit library stuff here.
I chose the direct wiring method, which works for me but may not work for everyone, because:
- The power consumption of the LEDs could overload the Raspberry Pi´s 5V outlet.
- The Raspberry Pi only provides 3.3V on its output pins, while the LED controller expects a level of 5V. Nevertheless, there are tolerances that may make it work with less than 5V. If it does not, then you need a level shifter.
Anyway, the "direct wiring" approach works for me.
(Please note the professional way of attaching with incredible amounts of hot glue.)
The Scroll pHAT only uses 3 GPIO pins (2, 3 and 5). According to Adafruit, "NeoPixels must be connected to GPIO10, GPIO12, GPIO18, or GPIO21 to work! GPIO18 is the standard pin.". I decided to connect:
- 5V to pin 4 (red line)
- GND to pin 34 (black line)
- Din to pin 40 / GPIO 21 (green line)
I like to run my Raspberry Pi´s with DietPi, a lightweight, minimal distribution. For the Scroll pHAT, i2c needs to be enabled, so make sure it is by running dietpi-config
and check Advanced Options - I2c state if it says "Enabled."
It is recommended to perform the following steps as the user dietpi
(not root
).
Install the requirements for Scroll pHAT:
curl https://get.pimoroni.com/scrollphathd | bash
- "Python3 is not installed. Would like to install it?” - yes
- “Do you wish to perform a full install? [y/N]” - yes
Install the requirements for WS2812B (aka NeoPixel):
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
The full install of the library provides example files in the home directory.
python3 ~/Pimoroni/scrollphathd/examples/swirl.py
To test the LEDs, I used the rpi_neopixel_simpletest.py example from Adafruit.
Within the script, set pixel_pin
and num_pixels
according to your setup (in this case here pixel_pin = board.D21
and num_pixels = 13
.
Be aware that the NeoPixel library needs root privileges to run.
sudo python3 rpi_neopixel_simpletest.py
(After closing the script, the LEDs stay on.)