Unicorn pHat on headless Pi0 (tea-time teaser)


When I start vncserver manually I can “sudo idle3” on the remote computer (VNC viewer 5.3.0 on win7). When I have vncserver starting up during boot I can’t “sudo idle3”, all I get is the following:

Client is not authorized to connect to ServerClient is not authorized to connect
to ServerTraceback (most recent call last):
File “/usr/bin/idle3”, line 5, in
File “/usr/lib/python3.4/idlelib/PyShell.py”, line1540, in main
root = Tk(className=“Idle”)
File “/usr/lib/python3.4/tkinter/init.py”, line 1854, in_init_
self.tk = _tkinter.create(screenName, baseName, className, interactive, want
objects, useTk, sync, use)
_tkinter.TclError: couldn’t connect to display “1.0”

I’ve tried

“sudo python3 phat_rainbow.py”

but it only partially works. Yes it runs the .py script, but not properly, rather than lighting up all the LEDs it only flashes a few at a time missing out the fourth row of LEDs.

Any ideas?

Thanks Andrew


Have you disabled analog audio?


how do I disable analog audio?


I think you can sudo nano /boot/config.txt and then add hdmi_drive=2, or alternatively do it through the Raspberry Pi configuration menu from the desktop.


Sorry Sandy no luck. The Unicorn pHat works fine when the Pi0 is plugged into an hdmi monitor and controlled remotely (with “hdmi_drive=2” both enabled and disabled) but not when headless.


Can you also try adding hdmi_force_hotplug=1 to /boot/config.txt, please?

That should force HDMI output even when there’s no HDMI cable plugged in.


I am getting really confused now …
I have tried uncommenting both “hdmi_drive=2” and “hdmi_force_hotplug=1” both together and each one in turn … with no joy. The unicorn phat just wont display properly when the hdmi cable is disconnected (before and during booting).
Now here is where it gets confusing … if I plug the Pi0 into an unpowered monitor (off at the mains) before booting and then SSH into the Pi0 the unicorn phat works fine using “sudo python3 phat_rainbow.py” at command prompt (in PuTTY) (it also works if I manually run vncserver and open a terminal window in vncviewer). The unicorn phat also works if I disconnect the hdmi cable after the Pi0 has finished booting.


Could you try commenting out the changes in /boot/config.txt and running:

curl -sS get.pimoroni.com/unicornhat | bash

… it should reimplement some of the changes @sandyjmacdonald recommended mind you, I just want to go back to a state closer to a freshly imaged Raspbian.

Once done, if it still does not work then please post the content of your /boot/config.txt


I don’t know what doing the above did … I don’t care. I now have a Unicorn pHat working as it should. However I think I know where I went wrong with Sandy’s suggestions. I simply uncommented them where they appeared in the config.txt rather than insert then at a specific point. Looking at the config.txt I found that the “hdmi_force_hotplug=1” was added onto the enable audio part (it wasn’t there before). That part of config.txt now looks like:

(HASH) Enable audio (loads snd_bcm2835)

Many thanks RogueM and sandyjmacdonald


I don’t think the order matters. But the ‘get’ installer does things a bit differently, part in the /boot/config.txt and part configuring the alsa mixer.

This means that if you want the analog audio back you won’t need to touch up the /boot/config.txt file, just use the lxpanel sound widget, or run:

 curl -sS get.pimoroni.com/audio | bash

basically choose HDMI option when you want to use the unicorn, analog if you want to route audio to speakers.