Phat installation issue


#1

Hi
I installed as the instruction but it isn’t working.
Whenever I tried different things, it opens Python window and says “======RESTART======”

Please help !!!
Many thanks.


#2

Ahoy,

Could you walk us through what pHAT you’re using, what you’re trying and what guide, if any, you’re following?


#3

Hello,

It is the Unicorn pHAT from Pimoroni and my system is pi 3.

I installed below from GitHUb.

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

It looked the installation was ok but it’s not working at all.

I downloaded examples but when I run, it say =====RESTART======

Many thanks for your help.


#4

you have to run unicorn as super user so you can use idle(python) through terminal by typing sudo idle and it should work. Else you could save the script and then run in terminal through sudo python myscriptname.py


#5

thanks for info.
sorry, i’m a very beginner.
just to recap… type sudo idle in the terminal.
once i entered, python window is up.
then what should i do?

thanks


#6

then you can program like normal and it should work as now that python window has all the sudo stuff in it to allow you to program the phat


#7

Hello all,

I had mass around for about 2 hours on weekend and the light came!
So it’s proved my soldering wasn’t the reason not working.

THIS IS WHAT I DID …

  1. Open the terminal and type
    sudo idle (no idea why but followed pi2003, thanks)

  2. Then type below on Python (Python window automatically up when I entered sudo idle on terminal)
    import unicornhat
    unicorn.set_layout(unicorn.PHAT)
    unicornhat.set_pixel(0, 0, 255, 255, 255)
    unicornhat.show()

Then one light turn up like a magic. Confident up then tried to run rainbow.py which is only official example provided by Pimoroni for pHAT (which is a shame, just ONE!)

  1. I tried both lines on both Python and Terminal but not working.
    sudo ./rainbow.py
    sudo python rainbow.py

  2. So I decided to type manually rainbow.py below on Python then NOT WORKING!!! WHY??? Anyone can help? This point I gave up after 5 hours in a bright sunny Sunday in front of Pi. I think Apple should step in this industry and make everything more intuitive and informative.

import colorsys
import math
import time

import unicornhat as unicorn

unicorn.set_layout(unicorn.PHAT)
unicorn.brightness(0.5)

print(“Reticulating splines”)
time.sleep(.5)
print(“Enabled unicorn poop module!”)
time.sleep(.5)
print(“Pooping rainbows…”)

i = 0.0
offset = 30
while True:
i = i + 0.3
for y in range(4):
for x in range(8):
r = 0#x * 32
g = 0#y * 32
xy = x + y / 4
r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0
g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0
b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0
r = max(0, min(255, r + offset))
g = max(0, min(255, g + offset))
b = max(0, min(255, b + offset))
unicorn.set_pixel(x,y,int®,int(g),int(b))
unicorn.show()
time.sleep(0.01)


#8

Welcome to the trial-by-fire of learning to program ;) Incidentally Apple are coming onto the scene, but it will be a long time before they have anything to mirror the depth and breadth of the Pi and its community :D in fact I think they’ll likely stick to a pure software approach.

There are more than just one example for the pHAT- all of the examples in the root folder should run on both HAT and pHAT: https://github.com/pimoroni/unicorn-hat/tree/master/examples

For future reference, when pasting code you can use three backticks ` to open and close a block of code.

like so

Which preserves whitespace.

It’s difficult to tell from your paste, but have you indented the example in the same way as it is in the original example? Python is… quirky… in that it treats indentation/whitespace as syntax. So:

while True:
    print("This")

Is different to:

while True:
print("This")

When you run your code, does anything happen? Does Python throw an error?


#9

It might be that you’re not in the right directory when running

sudo python rainbow.py

If you navigate using the folder browser to where rainbow.py is located and then go to “Tools > Open Terminal in this location” and then enter the above command you should have more luck?


#10

Just followed what you suggested and

IT WORKS !!! ^_^

Excellent.

Thanks for both major_tomm and gadgetoid.