New Unicorn Hat not working

Hello there,

some days ago I received my new Unicorn Hat, however, it does not work!

I put it on my Raspi 2, with Raspbian wheezy installed.

I followed the instructions on

and updated the System with
\curl https://get.pimoroni.com/uptodate | bash
beforehand.

I get the following error:

 pi@raspberrypi ~/Pimoroni/unicornhat $ sudo python ./simple.py
Traceback (most recent call last):
  File "./simple.py", line 3, in <module>
    import unicornhat as UH
  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

I don’t quite know what to do with that. I tried the solutions I found here in the forum, but to no avail.
Compared to others I’m a total newbie, so I’d appreciate a step-by-step solution, if there is any.

Anybody can help? Thanks!

I’d recommend trying the most up-to-date version of Raspbian Jessie rather than Wheezy.

Thanks for your suggestion. I just tried it on a freshly installed Jessie System and get the exact same error:

pi@raspberrypi:~/Pimoroni/unicornhat $ sudo python ./simple.py
Traceback (most recent call last):
File “./simple.py”, line 3, in
import unicornhat as UH
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

The steps I took beforehand were:
a) installation of Raspbian Jessie
b) Update with

\curl https://get.pimoroni.com/uptodate | bash

c) Installation of Unicorn Hat with

curl https://get.pimoroni.com/unicornhat | bash

What else can I do? Maybe the Unicorn Hat is broken?

I don’t think that would spit that error, I am able to run the simple.py program even when the HAT is not fitted.

I suspect it could be a dependency missing. could you post the output of:

pip list

also, it might be worth re-running

curl https://get.pimoroni.com/unicornhat | bash

… and review the entire output. There may be a clue as to what is causing the trouble.

Hello, thanks for your help.

I just ran the two suggested commands and pasted their output below. The only line which looked suspicious to me was this:

pi@raspberrypi:~ $ curl https://get.pimoroni.com/unicornhat | bash
bash: line 274: dt_check: command not found

The rest seems okay, however I cannot judge whether the dependencies are met.


pi@raspberrypi:~ $ pip list
argparse (1.2.1)
chardet (2.3.0)
colorama (0.3.2)
Flask (0.10.1)
gpiozero (1.2.0)
html5lib (0.999)
itsdangerous (0.24)
Jinja2 (2.8)
lxkeymap (0.1)
MarkupSafe (0.23)
mcpi (0.1.1)
ndg-httpsclient (0.3.2)
numpy (1.8.2)
picamera (1.10)
pifacecommon (4.2.1)
pifacedigitalio (3.1.0)
Pillow (2.6.1)
pip (1.5.6)
pyasn1 (0.1.7)
pygame (1.9.2a0)
pygobject (3.14.0)
pyOpenSSL (0.13.1)
pyserial (2.6)
requests (2.4.3)
rpi-ws281x (2.0.0)
RPi.GPIO (0.6.2)
RTIMULib (7.2.1)
sense-hat (2.1.0)
setuptools (5.5.1)
six (1.8.0)
spidev (3.0)
unicornhat (2.1.0)
urllib3 (1.9.1)
Werkzeug (0.11.9)
wheel (0.24.0)
wsgiref (0.1.2)

pi@raspberrypi:~ $ curl -sS get.pimoroni.com/unicornhat | bash
bash: line 274: dt_check: command not found

This script will install everything needed to use
Unicorn HAT

— Warning —

Always be careful when running scripts and commands
copied from the internet. Ensure they are from a
trusted source.

If you want to see what this script does before
running it, you should run:
\curl -sS get.pimoroni.com/unicornhat

Do you wish to continue? [y/N] y

Checking hardware requirements…
Done!

Checking install requirements…
Done!

Checking for Python 2 library…
Found!

Python 2 module found. Reinstall/Update? [y/N] y
Downloading/unpacking unicornhat
Downloading unicornhat-2.1.0.tar.gz
Running setup.py (path:/tmp/pip-build-YB8bMC/unicornhat/setup.py) egg_info for package unicornhat

Downloading/unpacking rpi-ws281x>=2.0.0 (from unicornhat)
Downloading rpi_ws281x-2.0.1.tar.gz (97kB): 97kB downloaded
Running setup.py (path:/tmp/pip-build-YB8bMC/rpi-ws281x/setup.py) egg_info for package rpi-ws281x

Installing collected packages: unicornhat, rpi-ws281x
Running setup.py install for unicornhat

Running setup.py install for rpi-ws281x
Compiling ws281x library…
building ‘_rpi_ws281x’ extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ilib/ -I/usr/include/python2.7 -c rpi_ws281x_wrap.c -o build/temp.linux-armv7l-2.7/rpi_ws281x_wrap.o
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/rpi_ws281x_wrap.o -Llib/ -lws2811 -o build/lib.linux-armv7l-2.7/_rpi_ws281x.so

Successfully installed unicornhat rpi-ws281x
Cleaning up…
Done!

Checking for Python 3 library…
Found!

Python 3 module found. Reinstall/Update? [y/N] y
Downloading/unpacking unicornhat
Downloading unicornhat-2.1.0.tar.gz
Running setup.py (path:/tmp/pip-build-iwtm_qmg/unicornhat/setup.py) egg_info for package unicornhat

Downloading/unpacking rpi-ws281x>=2.0.0 (from unicornhat)
Downloading rpi_ws281x-2.0.1.tar.gz (97kB): 97kB downloaded
Running setup.py (path:/tmp/pip-build-iwtm_qmg/rpi-ws281x/setup.py) egg_info for package rpi-ws281x

Installing collected packages: unicornhat, rpi-ws281x
Running setup.py install for unicornhat

Running setup.py install for rpi-ws281x
Compiling ws281x library…
building ‘_rpi_ws281x’ extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Ilib/ -I/usr/include/python3.4m -c rpi_ws281x_wrap.c -o build/temp.linux-armv7l-3.4/rpi_ws281x_wrap.o
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-armv7l-3.4/rpi_ws281x_wrap.o -Llib/ -lws2811 -o build/lib.linux-armv7l-3.4/_rpi_ws281x.cpython-34m.so

Successfully installed unicornhat rpi-ws281x
Cleaning up…

Examples already exist, shall I replace them? [y/N] y
Updating Unicorn HAT examples…
Cloning into ‘unicorn-hat’…
remote: Counting objects: 131, done.
remote: Compressing objects: 100% (116/116), done.
remote: Total 131 (delta 20), reused 63 (delta 10), pack-reused 0
Receiving objects: 100% (131/131), 327.24 KiB | 0 bytes/s, done.
Resolving deltas: 100% (20/20), done.
Checking connectivity… done.
I backed up the examples to unicornhat-backup, just in case you’ve changed anything!
Examples copied to /home/pi/Pimoroni/unicornhat/

Checking for additional software…
Done!

Finalising Install…

Reading package lists… Done
Building dependency tree
Reading state information… Done

All done!

Enjoy your new Unicorn HAT!

Maybe try cloning the repo from GitHub and installing the old fashioned way?

Type the following in a terminal:

git clone https://github.com/pimoroni/unicorn-hat.git
cd unicorn-hat/python/UnicornHat
sudo python setup.py install

Then, type:

cd ../examples
sudo python simple.py

Let us know how you get on with that.

Thanks for that idea. However, it lead to the same error. See below for the output.
Should I uninstall Unicorn Hat’s library beforehand? Or what else would you suggest?

pi@raspberrypi:~ $ git clone GitHub - pimoroni/unicorn-hat: Python library for Unicorn pHAT and HAT. 32 or 64 blinding ws2812 pixels for your Raspberry Pi
Cloning into ‘unicorn-hat’…
remote: Counting objects: 1181, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 1181 (delta 5), reused 0 (delta 0), pack-reused 1167
Receiving objects: 100% (1181/1181), 759.89 KiB | 0 bytes/s, done.
Resolving deltas: 100% (650/650), done.
Checking connectivity… done.
pi@raspberrypi:~ $ cd unicorn-hat/python/UnicornHat
pi@raspberrypi:~/unicorn-hat/python/UnicornHat $ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating unicornhat.egg-info
writing requirements to unicornhat.egg-info/requires.txt
writing unicornhat.egg-info/PKG-INFO
writing top-level names to unicornhat.egg-info/top_level.txt
writing dependency_links to unicornhat.egg-info/dependency_links.txt
writing manifest file ‘unicornhat.egg-info/SOURCES.txt’
reading manifest file ‘unicornhat.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
writing manifest file ‘unicornhat.egg-info/SOURCES.txt’
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib.linux-armv7l-2.7
copying unicornhat.py → build/lib.linux-armv7l-2.7
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
copying build/lib.linux-armv7l-2.7/unicornhat.py → build/bdist.linux-armv7l/egg
byte-compiling build/bdist.linux-armv7l/egg/unicornhat.py to unicornhat.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying unicornhat.egg-info/PKG-INFO → build/bdist.linux-armv7l/egg/EGG-INFO
copying unicornhat.egg-info/SOURCES.txt → build/bdist.linux-armv7l/egg/EGG-INFO
copying unicornhat.egg-info/dependency_links.txt → build/bdist.linux-armv7l/egg/EGG-INFO
copying unicornhat.egg-info/requires.txt → build/bdist.linux-armv7l/egg/EGG-INFO
copying unicornhat.egg-info/top_level.txt → build/bdist.linux-armv7l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents…
creating dist
creating ‘dist/unicornhat-2.1.0-py2.7.egg’ and adding ‘build/bdist.linux-armv7l/egg’ to it
removing ‘build/bdist.linux-armv7l/egg’ (and everything under it)
Processing unicornhat-2.1.0-py2.7.egg
Copying unicornhat-2.1.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding unicornhat 2.1.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/unicornhat-2.1.0-py2.7.egg
Processing dependencies for unicornhat==2.1.0
Searching for rpi-ws281x==2.0.1
Best match: rpi-ws281x 2.0.1
Adding rpi-ws281x 2.0.1 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Finished processing dependencies for unicornhat==2.1.0
pi@raspberrypi:~/unicorn-hat/python/UnicornHat $ cd …/examples
pi@raspberrypi:~/unicorn-hat/python/examples $ sudo python simple.py
Traceback (most recent call last):
File “simple.py”, line 3, in
import unicornhat as UH
File “build/bdist.linux-armv7l/egg/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

Out of interest, can you try running the example with the Unicorn HAT off your Raspberry Pi?

Actually, that probably makes no difference. I suspect you’ll still get the same error.

Can you post the output of uname -a?

Your guess was right. I get the same error message even when the Hat is off.

The output of uname -a is:

pi@raspberrypi:~/unicorn-hat/python/examples $ uname -a
Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux

I think there is a value trying with the HAT off. If nothing else we’ll know whether the error occurs regardless of this particular unit being used.

I get the same error when the Hat is off.

Hmm, what tells us that? Obviously the hardware and software requirements are met:
It’s a Raspi 2, with Raspbian Jessy installed, with all the software up to date.
The Unicorn Hat installation script has installed all the necessary software, hasn’t it? (see the output of pip list above)

So for the Unicorn python scripts it obviously makes no difference if the Hat is on or off, so maybe the error occurs because the Hat is not recognized at all. Because it’s broken?
I have no idea. Any more guesses?

I don’t think the HAT is the culprit, I do not get that error (or any error) running that script on a bare Pi. I tried with 3 different ones now, just to be sure, using a clean but updated Jessie.

I am not sure what the problem is, the main difference I can see between my tests and yours is that your Pi is obviously not the one I’m using. That’s not to say I think it’s defective, but it’s a possibility.

I think we need to summon the whiz @gadgetoid here to shed some light on the error itself… but from what I can tell the init can’t assess that PWM is working properly and I can reproduce the error if I target a pin other than 18.

Oh, that’s a possibility that hasn’t come to my mind yet. Apart from that the Pi is working fine, but maybe it’s the culprit.
Maybe gadgetoid can make sense out this all. Thanks so far.

Did this ever get resolved because I’m having the same problem and error code with the only difference being that my Raspberry Pi model is a B+ which I thought was more compatible with the Unicorn Hat anyway, but apparently not. I have tried your auto set-up command on multiple different images (fresh install) including the latest Raspbian Jessie, but to no luck I still get the same error message. I really don’t think my Raspberry Pi is broken as it is relatively unused, but maybe coincidentally me and bingobongo just got lucky with 2 broken models. My Unicorn Hat is brand new and came in the mail 2 weeks ago, but with multiple efforts to get it working I have had no luck. I would like if this issue could get re-looked at or at least get a status update and maybe get some comment from @gadgetoid if he hasn’t already starting looking in to it.

I believe this issue might be related: https://github.com/jgarff/rpi_ws281x/issues/93

IE: A driver level fix is required to get it up and running with whatever has changed recently. It’s on my TODO list.

I’ve pushed up rpi_ws281x v2.0.2 to, hopefully, fix this issue both on existing Pi’s and the new rev 1.3 Pi Zero which is also unknown to the library.

Try:

sudo pip install -I rpi_ws281x

It looks like there are two problems:

Garbled/intermittent display on Unicorn HAT/PHAT

On Raspbian 2016-05-10 / NOOBS 1.9.1 booting to X seems to do something with analog audio, where it would have otherwise been left alone and worked, mostly, by sheer luck. You need to force your Pi to HDMI audio using these lines in /boot/config.txt

hdmi_force_hotplug=1
hdmi_force_edid_audio=1

This pretends an HDMI monitor is plugged in, and that it supports audio.

You can also start in CLI mode, which doesn’t load whatever audio stuff is being used in X and has the same effect.

Failed with code -1

If you see something like ws2811_init failed with code -1 this is because you’re running an old version of the rpi-ws281x library on a Pi that it doesn’t recognize. This could be hardware version 0x13 which is a previously unsupported version of the Model B+ as far as I’m aware, or much more likely version 0x900093 which is the Raspberry Pi Zero v1.3 ( new model with camera port )

In this case, the instructions in my post above should work:

sudo pip install -I rpi_ws281x