Unicorn HAT HD 256 RGB Tutorials

Hello,

I recently got my Unicorn HAT HD 256 RGB from Pimoroni and I went through some example projects, I must say they are super cool. I am new to Python and have been searching the web for some good tutorials to begin with: Can you guys please guide me and point out few good tutorials to start programming my unicorn Hat HD?

Thank you,
W

1 Like

It’s for the original Unicorn HAT, but still applies with a little modification: https://learn.pimoroni.com/tutorial/unicorn-hat/making-rainbows-with-unicorn-hat

2 Likes

Unicorn HAT HD works in basically the same way as both Unicorn HAT and Unicorn pHAT, which just have less LEDs. We’ve got a Getting Started with Unicorn pHAT tutorial that should give you some tips.

But to get you started, if you open a terminal on your Pi and type the following, then it will light the top left LED in white:

import unicornhathd

unicornhathd.set_led(0, 0, 255, 255, 255)
unicornhathd.show()

So, the unicornhathd.set_led() function takes the following variables: x, y, r, g, b where x and y are the coordinates of the pixel from the top left corner beginning at 0, 0, and r, g, and b are red, green, and blue values from 0 to 255.

You can set any number of the pixels and then call unicornhathd.show() to push the data to the Unicorn HAT HD and display it. There are some tips in that Unicorn pHAT tutorial on how to use for loops to update groups of pixels all in one go too.

Just let us know if you need any more help, or if you have specific things you’d like to do. :-)

2 Likes

Thank you for the help. I am going to get back on my unicorn HAT HD today again and make some good pixel art.
Just one more quick question: Do I follow the same guidelines from unicorn HAT to light up rows and columns? Maybe draw a diagonal line :)

Thank you once again, Good Day!

1 Like

Yup, the API of Unicorn HAT HD is basically identical to that of Unicorn HAT- save for the fact it has 16x16 pixels instead of 8x8.

2 Likes

Guys,

Thank you for all the help. I have been busy with other projects and I will be working again on Unicorn HAT HD.

Good Day,
W

1 Like

Just a quick note to say that it’s set_pixel, not set_led - with that minor edit to Sandy’s example above, that script turns on the pixel at the corner closest to the Ethernet port on a Pi 3.

For those already comfortable with programming, there’s a useful reference manual here:
http://docs.pimoroni.com/unicornhathd/

1 Like

Hey, I’ve tried the example for the Unicorn Hat but changed the imported device to unicornhathd and tried the example for making a range of pixels flash but presently it just flashes the one pixel (0, 0), then flashes the next pixel to it (0, 1) and so one until all 256 pixels have flashed and then repeats.

Here’s what I’m typing currently:

import unicornhathd
import time

unicornhathd.brightness(0.5)

unicornhathd.rotation(0)

while True:
for x in range(16):
for y in range(16):
unicornhathd.set_pixel(x, y, 255, 50, 100)
unicornhathd.show()
time.sleep(0.25)
unicornhathd.clear()
unicornhathd.show()
time.sleep(0.25)

(Please note I’m typing this on my phone and so the spacing isn’t correct here)

Am I missing a step?

Thanks!

Dani

Never mind, it was my mistake! I was due to the spacing I made in Thonny; the ‘unicornhadhd.show()’ was in-line with the set pixel command and should had been set inline with ‘for x in range(16):’ - just like in the example… 😳

Flashing like a little trooper now!

Thanks!