Getting the Unicorn Hat up and running

Hey guys,

I got my Unicorn last week hat and have gone over to the github and played around with a few tests - i.e etc etc. I was wondering if there is any more info around for configuring the hat… I’m trying to test out the full power of all the LEDs at once and am struggling to find any help out there… what’s the best approach and are there any tutorials out there that any of you may have seen?

I’ve also tried to compile the original drivers in C from here: but this isn’t going well at all (the Pi just crashes when I try and paste in the code, so actually haven’t even gotten to the stage of compiling anything)

thanks in advance - v much looking forward to seeing this baby glow in all it’s glory!


Hey there!

So you have got your Unicorn HAT up and running but you now want to unleash the full fury of its rainbow onslaught?

Hey Jon,

Thanks for replying!

yes indeed I want to unleash the rainbow beast! I discovered the .brightness function… (which has made me super happy) through playing with some of the example python scripts on github, but would love to know if there is a repository of all the commands available. I’m currently using the .brightness function but with a timer. I realise that this probably says more about my lack of python/general scripting skills but any help GREATLY appreciated! I’m not just waiting for a ready-made solution - I’m keen to get stuck in and learn through doing but a couple of pointers would be fanttastic! Many thanks! ! !

Also - on a sidenote … is the Unicorn Hat compatible with Arduino? Would it behave like the NeoPixel shields built for Arduino (i.e Adafruit’s NeoPixel shield here: ) ??

Thanks again!


Ahoy @jedisha!

It would appear I’ve got some more documenting to do!

For the time being, however, you can find all of the functionality available in the library by peering into the source files themselves:

There isn’t much there beyond setting a pixel to a particular colour, the rest ( drawing functions, patterns, etc ) you’ll have to build on top of the basic library yourself!

The .brightness() function is, indeed, what you’re looking for. It takes a value between 0.0 and 1.0, so 0.5 is “half” brightness and 1.0 is full. I’m interested to know why you use a timer with this?

The Unicorn Hat is compatible with Arduino. I’ve tried this myself with an ATtiny. Just hook up your board to the VCC/DIN/GND pins supplied, and use the regular NeoPixel Library. I think NEO_GRB and NEO_KHZ800 are the settings you’ll need.


Thanks so much @gadgetoid!!!
Will hopefully get a chance to play with this one evening this week.

I don’t actually want the timer in the sketch, it was in there already and I modified it but left it in… Still early days for me and my burgeoning relationship with python!!

Thanks again, will let you know how it goes!

1 Like


I too bought the Unicornt Hat but I am struggling to get it up and running. I have followed the instructions for beginners on but I get errors about python not being able to install properly.

I am also struggling to understand what the WS2812 driver is, and how to install it.

Any pointers would be greatly appreciated so I can start using my new Unicorn Hat.


Can you screenshot or copy&paste the errors you’re getting?

Does this installer work;

\curl -sS | bash

I have ran that command and that’s when I get errors about python being installed. I will get a screenshot tonight when I set it up as I’m about to head to work. Also, do I need to install anything related to the WS2812 drivers to get it working?

Nope, everything should be installed automagically when you run the Unicornhat installer. You shouldn’t need to worry about drivers of any sort.

Ok. Well I’ve tried that and it’s not working properly - I will take a look at the error and screenshot it later tonight to see if that helps. I did manage to get some of the unicorn hat lights to work last night by running one of the python scripts, but it only worked on 1 third of the hat instead of using all of the LED’s.

I will report back, but if this info above helps in any way then I’d be happy to hear.


Did you run by any chance?

In my infinite wisdom I mapped Hue, Saturation and Value across the screen- the upshot of this is that half the LEDs don’t get lit because they’re too desaturated to be a visible colour.

Sounds like you had it working fine, though, it’s just that script is an awful red-herring which I regret ever writing :D I’ll patch it today.

I don’t think it was, but I can double check tonight when I fire up the Pi again.

My Pi is currently set up as a retro games console running Emulation Station. My thinking is that I would like to use the Unicorn Hat to display a graphic depending on which games console is being emulated (i.e. a mushroom for Nintendo etc.), but this is some way off yet!

I was going to give it a go again tonight and also try a fresh Raspbian image to try and identify why it is not working.

I’ll post the screenshot of the error later as that should help!

Thanks for your help so far though.

Ok, so I get this when I try to run one of the example python scripts:

Traceback (most recent call last):
File “”, line 3, in
import unicornhat as unicorn
File “/usr/local/lib/python2.7/dist-packages/”, line 1, in
import ws2812, atexit
ImportError: No module named ws2812

(Sorry I can’t upload a screenshot, it says new users cannot do it!).

However, I pulled the files from and then when I input “sudo ./ws2812-RPi” this is when the unicorn hat starts to work, but only lights up three of the eight rows…

Any ideas?

EDIT: Ok, so I have installed a fresh Raspbian image and it now works. Must be a problem somewhere in my Emulation Station setup, but not sure where. If the error message above means anything, then would be happy to hear but if not then I’ll start again with Emulation Station and see what happens.

Sounds like it was a problem installing the python libraries- I’d guess the ws2812 module didn’t compile properly. For future references, you can force a reinstall of Python libraries using the I ( capital i ) flag when using pip and then watch out for any compile errors due to missing headers and whatnot ( usually python.h which is supplied by python-dev )

I think, by default, the original 626Pilot code doesn’t drive 64 ws2812 LEDs in a chain, so it’ll only light up however many it’s set to.

Ok, thanks.

I will try to force a reinstall later using the -I flag and see what happens.

Not sure if this is relevant, but when I run the script

\curl -sS | bash

and it starts searching for Python, it gives me the option to reinstall / update. If I press “Y” to do this, I get an error too (will try and replicate it again later and post on here). I seem to remember it talks about a log file (.tmp?) and to check that for more details etc…

Would using the -I flag give me the same result, or is that somehow different?

When you choose to re-install using the setup script, it will set the -I flag for you. So if it’s still failing, then it’s likely you’re either missing a dependency that I’ve overlooked, or Pip can’t talk to the remote server- the latter tends to happen if you’re behind a firewall/proxy in an office/college/school/university.

Ok, that makes sense.

I don’t think it is anything to do with the network as when I set it up using a fresh Raspbian install, everything worked smoothly and first time. Must be something on my Pi screwing things up - I think the error message might help, so will post that tonight again.

Thanks again for your help so far! Would be great if I can get it sorted, otherwise it might need a new setup of Emulation Station along with the Unicorn Hat, which would be a lot of work, so if I can prevent that then I would be happy!

Sorry about the delay - been a bit busy this week!

I have just tried the install on a backup image of my Emulation Station setup from before I installed a few other tweaks to see if that caused the problem. I’ve just run your install script and this is the error I get:

Installing collected packages: unicornhat, ws2812
Running install for unicornhat

Running install for ws2812
building ‘_ws2812’ extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ilib/ -I/usr/include/python2.7 -c lib/ws2812-RPi.c -o build/temp.linux-armv6l-2.7/lib/ws2812-RPi.o
unable to execute gcc: No such file or directory
error: command ‘gcc’ failed with exit status 1
Complete output from command /usr/bin/python -c “import setuptools;file=’/home/pi/build/ws2812/’;exec(compile(open(file).read().replace(’\r\n’, ‘\n’), file, ‘exec’))” install --single-version-externally-managed --record /tmp/pip-rG3AvG-record/install-record.txt:
running install

running build

running build_py

creating build

creating build/lib.linux-armv6l-2.7

copying -> build/lib.linux-armv6l-2.7

running build_ext

building ‘_ws2812’ extension

creating build/temp.linux-armv6l-2.7

creating build/temp.linux-armv6l-2.7/lib

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ilib/ -I/usr/include/python2.7 -c lib/ws2812-RPi.c -o build/temp.linux-armv6l-2.7/lib/ws2812-RPi.o

unable to execute gcc: No such file or directory

error: command ‘gcc’ failed with exit status 1

Command /usr/bin/python -c “import setuptools;file=’/home/pi/build/ws2812/’;exec(compile(open(file).read().replace(’\r\n’, ‘\n’), file, ‘exec’))” install --single-version-externally-managed --record /tmp/pip-rG3AvG-record/install-record.txt failed with error code 1 in /home/pi/build/ws2812
Storing complete log in /root/.pip/pip.log
Python 2 library install failed!

This is where the install fails and nothing else works.

Any suggestions?

This would be the pertinent line, it looks like the compiler isn’t even installed. I haven’t added checks to the install scripts for this because it’s always installed in Raspbian as far as I’m aware.

I think you need to:

sudo apt-get install build-essential


sudo apt-get install gcc

Did you use the Emulation Station SD card image to set it up? I’ve not actually played with that yet, but it looks flippin’ cool! I haven’t seen a good set of emulator front-ends since Robert Broglia’s “.emu” emulators, which are amazing:

Thanks - I tried both those commands and it tells me that build-essentials is already the newest version and the same with gcc.

So basically it looks like both are installed, which is odd…

When I run your script, if I say no to reinstalling / updating Python, then it completes and tells me everything is fine - it also downloads flask and then completes as normal (like when I did this on a fresh Raspbian image). But when I try and run one of the example scripts, I get:

Traceback (most recent call last):
  File "", line 3, in <module>
    import unicornhat as UH
  File "/usr/local/lib/python2.7/dist-packages/", line 1, in <module>
    import ws2812, atexit
ImportError: No module named ws2812

Is there a way I can install things manually? Perhaps the Emulation Station image has things in different directories and is causing problems with the script?

And yes, I used the ES SD card image to set it up - it is fantastic and the UI is amazing! There was a lot of tweaking to get everything to look and run smoothly (which is why I didn’t really want to start from scratch again if possible), as I now have my emulators running in full screen, no sound issues, have my PS3 controller working via Bluetooth and all the buttons mapped for each emulator. I would highly recommend it and if you needed any pointers there, then feel free to let me know!