Unicorn pHAT and zero w (mood light kit)

Sooo… got my daughter a mood light for her birthday. She absolutely loves it!


We did have to substitute in a spare old-style pi zero that I had lying around though. Because when I try to run the unicorn phat from the pi zero w, I get the following error:

Traceback (most recent call last):
File “rainbow.py”, line 6, in
import unicornhat as unicorn
File “/usr/local/lib/python2.7/dist-packages/unicornhat.py”, line 14, in
ws2812.begin()
File “/usr/local/lib/python2.7/dist-packages/neopixel.py”, line 114, in begin
raise RuntimeError(‘ws2811_init failed with code {0}’.format(resp))
RuntimeError: ws2811_init failed with code -1
Exiting cleanly

This was using a freshly-minted raspbian SD card, fully updated, with brand new Pimoroni dashboard installed, and unicorn pHAT support installed via dashboard. Obviously not a problem with the unicorn pHAT, as it works fine on the old pi zero. And just to be sure, I tried it with another unicorn pHAT that I already had (and have used many times), and same error. So… I thought maybe there was a problem with my soldering of the headers on the pi zero w. But I set up a simple circuit with an LED and resistor, and can confirm that the 1st 5V pin works, and BCM 18. (I think these are what the unicorn pHAT uses.)

I’ve just had a look at it again today, and updated and upgraded raspbian (seems quite significant, with added bonus that onboard LED works properly now), but still getting same error with unicorn pHAT. I think it must be something I’m doing, because no one else is reporting these problems, but I’m a a loss as to what it is!

The pi zero w seems to work fine apart from this. I’ve just got a couple of other pHATs today (that were intended for an old pi zero), so may get a chance to test them tomorrow.

Have fun at the big birthday. Wish I was there instead of organising a kid’s birthday!

I can also confirm this behaviour. Fresh raspbian-lite (downloaded yesterday) on a mood light kit with an additional sandisk SD card & offical RPi power supply.

uname -a:

Linux raspberrypi 4.4.50+ #970 Mon Feb 20 19:12:50 GMT 2017 armv6l GNU/Linux

cat /proc/cpuinfo | grep Revision:

Revision        : 9000c1

I installed Unicornhat by following the getting started guide (learn.pimoroni.com/tutorial/unicorn-hat/getting-started-with-unicorn-hat):

curl -sS get.pimoroni.com/unicornhat | bash

And when it didn’t work, I found this answer from @gadgetoid, so I’ve tried running:

sudo pip uninstall rpi_ws281x
sudo pip3 uninstall rpi_ws281x
sudo pip install rpi_ws281x
sudo pip3 install rpi_ws281x

and confirmed that the rpi_ws281x versions are 2.0.4 which seems to have the ZeroW defined (github.com/pimoroni/unicorn-hat/blob/master/library/rpi-ws281x/lib/rpihw.c).

I’ve run sudo apt-get update && sudo apt-get upgrade successfully with no errors, to no avail.

I’ve made sure I have the most up to date unicornpy (2.1.2) with both

sudo pip install -I unicornhat
sudo pip3 install -I unicornhat

but running any combination of:

cd ~/Pimoroni/unicornhat/examples
sudo ./rainbow.py
sudo python rainbow.py
sudo python3 rainbow.py

gives the same result:

Traceback (most recent call last):
  File "rainbow.py", line 6, in <module>
    import unicornhat as unicorn
  File "/usr/local/lib/python2.7/dist-packages/unicornhat.py", line 14, in <module>
    ws2812.begin()
  File "/usr/local/lib/python2.7/dist-packages/neopixel.py", line 114, in begin
    raise RuntimeError('ws2811_init failed with code {0}'.format(resp))
RuntimeError: ws2811_init failed with code -1
Exiting cleanly

(except python3 which lists python3.4 instead of python2.7)

What’s the next step to chasing the source of this error?

Glad to hear it’s not just me!

Phil Howard’s already aware (via twitter) that I’m having problems, but he and a good proportion (if not all) of the Pimoroni crew are in Cambridge for the birthday bash this weekend, so a fix before Monday is unlikely…

I figured that they might be a little busy this weekend!

1 Like

I’ll speak to Phil tomorrow. He or I will update this topic when a fix is up.

1 Like

As per the pinned message, we’ve found the root cause of this problem now, and the solution. Open a terminal and type sudo pip install --upgrade rpi_ws281x to fix the rpi_ws281x dependency.

Confirmed, works lovely for me with v2.0.5. I should also point that python3 will need:

sudo pip3 install --upgrade rpi_ws281x

It caught me out for a minute!

Brilliant. I decided to just leave the old pi zero on my kit, as I don’t really need the wireless with it, and am using the zero w for better things anyway :) (Currently blinding my office mate with a set of motes and scroll pHAT HD.)