Having some issues with the UnicornHat

When I import the unicornhat module, I receive the following error message:

Traceback (most recent call last):
File “/home/pi/test.py”, line 2, in
import unicornhat as uh
File “/usr/local/lib/python3.5/dist-packages/unicornhat.py”, line 35, in
File “/usr/local/lib/python3.5/dist-packages/rpi_ws281x/rpi_ws281x.py”, line 130, in begin
raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -5 (mmap() failed)

I have tried this on multiple raspberry pi 3 b cards and get the same behavior. I am using stretch raspbian. I installed by running and saying yes to everything (including audio and full install):

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

I have commented out these lines in my config.txt:


in the hopes that something audio-related was causing the issue. When I place the hat on my rpi I don’t see any lights by default. Is that expected? I have pushed the hat down pretty far, but you can see a little bit of the GPIO pins, should it be all the way down?

Thanks for the help.

Just want to confirm you have the Unicorn, not the Unicorn HD?
I have a Unicorn HD, it doesn’t light up until you command it to.
It has a low profile SMT header, Its not as deep as the solder on through hole header. So seeing some bare copper is normal, don’t force it.

In all cases you must run your Unicorn HAT code as root, since it does weird and wonderful things with the Pi’s hardware that a normal user is forbidding from doing.

IE: sudo python myscript.py

Or if you’re playing with the REPL: sudo pythonimport unicornhat

Or if you’re using IDLE/IDLE3 sudo idle rather than launching it from the Pi menu.

Thanks! That did it. I’m loving it! My students will have a blast.