Unicorn PHAT only works with terminal and Sudo?


#1

Hey everone, I am trying to write scripts for the moodlight in IDLE, but it simply doesn’t work. it forces to me run the terminal first and sudo idle instead of allowing me to just jump straight into idle through the task bar… any ideas on why? This might cause issues with some things i want to do down the line


#2

It’s a limitation of the way Unicorn HAT and pHAT works, it needs low level access to the hardware which, in turn, requires root privileges. One solution to this would be to run a script continuously as root (a daemon) and communicate to that from your less privileged python process.


#3

oh! Thanks for the tip! uh…how do I do that? XD


#4

There’s the rub, it’s easier said than done but I appreciate you might not always want to run your script as root.

The trick is to have one Python script run as root and accept a stream of data somehow from another script. This is often accomplished via sockets: https://docs.python.org/2/howto/sockets.html

Someone actually made a C server for exactly this a while ago, but I fear it might have fallen into disrepair: https://github.com/pimoroni/unicorn-hat/tree/master/library_c/unicornd


#5

Okay I’ve updated unicornd so it’s got a good chance of building. See the build instructions in the readme here: https://github.com/pimoroni/unicorn-hat/tree/master/library_c/unicornd

Then run it and try the python demo here: https://github.com/pimoroni/unicorn-hat/tree/master/library_c/unicornd/test_client