Unicorn Hat not working ws2811_init not working

I just got a new Unicorn hat and i am encountering

 Traceback (most recent call last):
  File "./paint.py", line 13, in <module>
     import unicornhat as unicorn
  File "build/bdist.linux-armv7l/egg/unicornhat.py", line 16, in <module>
  """
  File "build/bdist.linux-armv7l/egg/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 know that this has been discussed in prior threads:
[Unicorn HAT no longer working after Raspbian upgrade]
(Unicorn HAT no longer working after Raspbian upgrade)

but if someone could tell me simply what i would have to do to get the hat working then that would be great, i’m very new to all this so step by steps would be amazing. thanks!

I’m using a raspberry pi 3

Interesting, this shouldn’t happen anymore for all the reasons I’ve come across- it’s possibly the error could be one we haven’t come across since the error code -1 is the code returned for every possible error in ws2811_init ( something I’ve been meaning to fix for a while for better debugging! ).

What version of Raspbian are you running, and which Raspberry Pi?

Actually, a hunch; You don’t happen to have a new 512mb A+ do you?

Im running raspbian 4.4.11-v7+
Im using a raspberry pi 3

Any help you could offer?

I’m in the process of rewriting the error handling so we can actually figure out what’s going wrong, rather than guessing.

Since some of the errors are difficult for me to intentionally generate for testing, I’d appreciate your input.

Could you try grabbing my fork from here: https://github.com/Gadgetoid/unicorn-hat/

And just cd into library/rpi-ws281x and run: sudo python setup.py install to update the underlying “neopixel” library.

Then try running Unicorn HAT again.

Thank you for helping me, sorry I was just a little sad that my unicorn hat wasn’t working but I really appreciate your help.

I ran this code on the github page:

\curl -sS get.pimoroni.com/unicornhat | bash
Install from Github clone

git clone https://github.com/pimoroni/unicorn-hat
cd unicorn-hat/
sudo apt-get install python-dev
cd library/rpi-ws281x
sudo python setup.py install
cd ../..
cd library/UnicornHat
sudo python setup.py install
cd ../..

and this is what i got when i tried to run unicornpaint again:

pi@raspberrypi:~/Pimoroni/unicornhat/examples/hat/unicornpaint $ sudo ./paint.py
Traceback (most recent call last):
  File "./paint.py", line 13, in <module>
    import unicornhat as unicorn
  File "build/bdist.linux-armv7l/egg/unicornhat.py", line 16, in <module>
    """
  File "build/bdist.linux-armv7l/egg/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

You’ll need to grab:

And not:

If it works, you’ll see an error code other than -1.

I’m not sure what was in the git that you told me to copy but it finally got the hat up and working. I was able to use the rainbow.py file and have the hat light up!

Is there a way to have the unicorn paint service run on system startup?

Well, that was unexpected!

That Git is my current working copy of the Unicorn HAT library, with some changes to error reporting that I’m working on. It’s also based upon a slightly newer version of the rpi_ws281x code, so there must have been a fix for your particular setup in there.

The quick and dirty way to get a Python script running at startup is just to call it from /rc/rc.local - a practise I use for demo setups, where I’m not going to be using the Pi any other way. Something like:

sudo python /home/pi/path/to/unicorn-paint.py

If a script requires, for some reason, a particular working directory I will call a bash script instead, which would look something like:

cd /home/pi/path/to/
sudo python unicorn-paint.py

It’s possibly that this method might work on a Pi too, and would be the more proper way to do it ( on Raspbian Jessie anyway ): How to setup a service to automatically run a python script when the BeagleBone Black (BBB) reboots. These instructions allow you to setup a python script to automatically start when the BeagleBone (running Angstrom linux with systemd) restarts. · GitHub

1 Like

Alright good to know in case I need it in the future. Thanks again for helping me get this up and running ! :)