Unicorn Hat Sample Scripts... 'Failed to open/dev/mem'


I’ve just received a Unicorn Hat for my Raspberry Pi B+ and used ‘\curl -sS get.pimoroni.com/unicornhat | bash’ to install all of the dependencies, sample code, etc. However when I try to execute the sample scripts I get a ‘Failed to open /dev/mem: Permission denied’ error.

I can run the scripts if I use sudo but I’m guessing that this isn’t usual/right.

Does anyone know what I’ve done wrong and how I can possibly fix it?

I’m logging into my Pi as a user called simon which is a sudoer but wanted to mention it incase it is related to not being logged in as ‘pi’.

Many thanks.


First off, welcome to the world of Pi!

If you’ve got any previous linux experience you might find the norm of prefixing basically everything with “sudo” a little disconcerting… but hey, it works!

Try this:

sudo ./scriptname.py

Yup, it’s odd! But using sudo has absolutely become the norm for Pi. For better or worse. It’s probably going to teach people some bad habits but the Pi community has pretty much painted itself into a corner on this one!


Thank you for the welcome, the speedy reply and the clarification. If sudoing is the Pi norm then who am I to buck the trend. :-)