Unicorn hat issues


I have been using the unicorn hat to light up inside a sign for 10 seconds whenever I get a specific email, a cron job runs every 15 seconds to check my email and runs the python file if the email is unread, and then archives it, Now I tried to implement noise with this by using an HDMI to 3.5mm output adapter, and now the unicorn hat will not work properly, even after reinstalling raspbian, buying another unicorn hat to test, idk what is going on. Now when I get an email, it will light up, but then if I get another email it will either not run, and show one single red light in the corner, or run, flash, run and then not light up with the red dot. whats going on?

Here is the code

import gmail
import unicornhat as unicorn
from light import light
from time import sleep

g = gmail.login()
unread = g.inbox().mail(subject="[Ardent Ink] Order")
print unread[0].body
total_messages = 0

new email

for message in unread:
total_messages += 1

if total_messages > 0:
print (‘light run is successful’)

emails = g.inbox().mail(subject="[Ardent Ink] Order")
for email in emails:
print (‘email is archived’)

and the light file that is imported

import time
import unicornhat as unicorn

def light():
width,height= unicorn.get_shape()

for y in range(height):
	for x in range(width):



You should use 3 backticks to format your code, like this:

def hello_world():
    print("Hello world!")

Looking over it, I don’t see anything to produce sound?

What you describe is a pretty classic case of the Pi activating, or trying to do something over the analog audio with predictably unpredictable results.

You may need a combination of htmi_force_hotplug and some other tweaks to ensure the Pi doesn’t try to do anything with the PWM it uses to create analog audio- since Unicorn HAT needs it.

We have a one-line installer for configuring audio which may help:

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


Thanks for the response, yeah I took out the audio code. I think that it is doing that when it gets multiple emails in a row, it gets really glitchy, either with flashing, the light just staying on, or it doesn’t turn on at all, maybe the unicorn hat isnt meant for this type of thing, to be turned on and off as a notification light.


there should be absolutely no problem doing this.

But, as per @gadgetoid suggestion, and you talking about an HDMI to 3.5mm adapter, we need to know how you have configured your audio, and what hardware you aim to use to produce sound otifications - this is almost certainly the issue.


I am not even concerned with the sound anymore, the issue is the unicorn hat has no rhyme or reason to if it will light up or not now. I have nothing sound wise plugged into it, and HDMI is selected on audio on the raspberry pi, but somehow it still bugs out - I am not sure why this is happening, other than maybe the code is somehow overloading the unicornhat.


selecting HDMI is not sufficient, see @gadgetoid link to our audio script - you need to force route, not just use the Pi panel to select the output.

But sure, it could be something to do with the code… do the examples from the unicornhat repo produce the same haphazzard results?


I did that, and yes they do, for example I ran rainbow.py without a problem but then ran drop.py and got nothing, followed by an single dot in the corner, and then tried to run rainbow.py again and it didn’t work.