<commit_before>---
layout: post
title: Controlling the Pimoroni Unicorn HAT with the Skywriter
---

A few days ago, I tweeted a [Vine clip](https://vine.co/v/OXVehbD6T6q) 
showing the [Pimoroni](http://shop.pimoroni.com) Unicorn HAT LED matrix 
being controlled with the Skywriter HAT. Well, the Pimoroni guys retweeted 
it and then asked if I would write up how I'd done it. I'll try to explain 
it all, with what you'll need, how to connect everything up, install the 
software, and how the code works.

Here's what it looks like in action.

![Unicorn HAT and Skywriter]({{ site.url }}/assets/unicorn_skywriter.gif)

Here goes with the tutorial. It might get long.

## I <3 Pimoroni

I have a bit of a man crush for Pimoroni. Their recent HATs (Hardware
Attached on Top) for the Raspberry Pis A+ and B+ are just beautiful. They
really nailed every detail of them, from the gorgeous matte black PCBs down
to the product names, the typography and images on the PCBs and the libraries
they provide on GitHub to control the HATs.

When Pimoroni brought out their 8x8 neopixel LED matrix, the [Unicorn 
HAT](http://shop.pimoroni.com/products/unicorn-hat), I hacked together a short 
Python script that would blink a spot on and off, and then when they brought 
out their 3D gesture-sensing addon, the [Skywriter HAT]
(http://shop.pimoroni.com/products/skywriter-hat), it occured to me that I 
could use it to control the Unicorn HAT. The only problem being, how could I 
connect both HATs at the same time? Enter the Black HAT Hack3r.

The [Black HAT Hack3r](http://shop.pimoroni.com/products/black-hat-hacker) 
is another Pimoroni product that allows you to mount a HAT separately to your 
Raspberry Pi via a ribbon cable but still access all 40 of the GPIO pins for 
whatever purpose you wish. With two Black HAT Hack3rs you have the perfect way 
to link two HATs at the same time to your Raspberry Pi.

## What you'll need

* A Raspberry Pi A+ or B+ with 5v power supply
* At least one Black HAT Hack3r (BHH from here on in)
* A Unicorn HAT
* A Skywriter HAT
* A few female-to-female jumper wires
* A finger

## Installing the software

First, you should run a `sudo apt-get update` and `sudo apt-get upgrade` to
make sure that everything is up-to-date on your Raspberry Pi operating system.

Next, you'll need to install the libraries for the Unicorn HAT and Skywriter
HAT. There are various ways to do this.

### Unicorn HAT

For the Unicorn HAT you can either:  
`sudo pip install unicornhat`  
**or**  
`git clone https://github.com/pimoroni/UnicornHat.git`  
and then  
`cd UnicornHat/python/UnicornHat`  
and  
`sudo python setup.py install`  
**or**  
`\curl -sS get.pimoroni.com/unicornhat | bash`  
which will walk you through the full install.

### Skywriter HAT

For the Skywriter HAT, you can either:  
`sudo pip install skywriter`  
**or**  
`git clone https://github.com/pimoroni/skywriter-hat`  
and then  
`cd skywriter-hat/python/library`  
and then  
`sudo python setup.py install`

### numpy

You'll also need to install numpy by:  
`sudo pip install numpy`

## Connecting it all up

I'll assume you've soldered the 40 pin headers to your BHHs.
If not, get soldering, it takes a while.

You'll want to plug your Unicorn HAT into one BHH and the Skywriter into the 
other.

Since the Skywriter uses more pins than the Unicorn HAT (the Unicorn HAT uses
just three), you'll want to connect the BHH with the Skywriter on to your
Raspberry Pi with the 40 pin ribbon cable that came with your BHH.

Next, you'll need to connect three female-to-female jumper wires from the 
breakout pins on the BHH with the Skywriter on to either the input pins or
breakout pins on the BHH with the Unicorn HAT on. The Unicorn HAT uses just 
the 5V pin (2 or 4), ground pin (6, 9, 14, 20, 25, 30, 34 or 39) and GPIO
pin 18 (12).

You'll see how mine is connected up in the image below.

![Unicorn HAT and Skywriter setup]({{ site.url }}/assets/unicorn_skywriter_setup.jpg)

Before you go any further, it's probably a good idea to test that your Unicorn
HAT and your Skywriter HAT are both still working properly by running one of 
the example scripts for both.<commit_msg>Added pin numbers<commit_after>---
layout: post
title: Controlling the Pimoroni Unicorn HAT with the Skywriter
---

A few days ago, I tweeted a [Vine clip](https://vine.co/v/OXVehbD6T6q) 
showing the [Pimoroni](http://shop.pimoroni.com) Unicorn HAT LED matrix 
being controlled with the Skywriter HAT. Well, the Pimoroni guys retweeted 
it and then asked if I would write up how I'd done it. I'll try to explain 
it all, with what you'll need, how to connect everything up, install the 
software, and how the code works.

Here's what it looks like in action.

![Unicorn HAT and Skywriter]({{ site.url }}/assets/unicorn_skywriter.gif)

Here goes with the tutorial. It might get long.

## I <3 Pimoroni

I have a bit of a man crush for Pimoroni. Their recent HATs (Hardware
Attached on Top) for the Raspberry Pis A+ and B+ are just beautiful. They
really nailed every detail of them, from the gorgeous matte black PCBs down
to the product names, the typography and images on the PCBs and the libraries
they provide on GitHub to control the HATs.

When Pimoroni brought out their 8x8 neopixel LED matrix, the [Unicorn 
HAT](http://shop.pimoroni.com/products/unicorn-hat), I hacked together a short 
Python script that would blink a spot on and off, and then when they brought 
out their 3D gesture-sensing addon, the [Skywriter HAT]
(http://shop.pimoroni.com/products/skywriter-hat), it occured to me that I 
could use it to control the Unicorn HAT. The only problem being, how could I 
connect both HATs at the same time? Enter the Black HAT Hack3r.

The [Black HAT Hack3r](http://shop.pimoroni.com/products/black-hat-hacker) 
is another Pimoroni product that allows you to mount a HAT separately to your 
Raspberry Pi via a ribbon cable but still access all 40 of the GPIO pins for 
whatever purpose you wish. With two Black HAT Hack3rs you have the perfect way 
to link two HATs at the same time to your Raspberry Pi.

## What you'll need

* A Raspberry Pi A+ or B+ with 5v power supply
* At least one Black HAT Hack3r (BHH from here on in)
* A Unicorn HAT
* A Skywriter HAT
* A few female-to-female jumper wires
* A finger

## Installing the software

First, you should run a `sudo apt-get update` and `sudo apt-get upgrade` to
make sure that everything is up-to-date on your Raspberry Pi operating system.

Next, you'll need to install the libraries for the Unicorn HAT and Skywriter
HAT. There are various ways to do this.

### Unicorn HAT

For the Unicorn HAT you can either:  
`sudo pip install unicornhat`  
**or**  
`git clone https://github.com/pimoroni/UnicornHat.git`  
and then  
`cd UnicornHat/python/UnicornHat`  
and  
`sudo python setup.py install`  
**or**  
`\curl -sS get.pimoroni.com/unicornhat | bash`  
which will walk you through the full install.

### Skywriter HAT

For the Skywriter HAT, you can either:  
`sudo pip install skywriter`  
**or**  
`git clone https://github.com/pimoroni/skywriter-hat`  
and then  
`cd skywriter-hat/python/library`  
and then  
`sudo python setup.py install`

### numpy

You'll also need to install numpy by:  
`sudo pip install numpy`

## Connecting it all up

I'll assume you've soldered the 40 pin headers to your BHHs.
If not, get soldering, it takes a while.

You'll want to plug your Unicorn HAT into one BHH and the Skywriter into the 
other.

Since the Skywriter uses more pins than the Unicorn HAT (the Unicorn HAT uses
just three), you'll want to connect the BHH with the Skywriter on to your
Raspberry Pi with the 40 pin ribbon cable that came with your BHH.

Next, you'll need to connect three female-to-female jumper wires from the 
breakout pins on the BHH with the Skywriter on to either the input pins or
breakout pins on the BHH with the Unicorn HAT on. The Unicorn HAT uses just 
the 5V pin (2 or 4), ground pin (6, 9, 14, 20, 25, 30, 34 or 39) and GPIO
pin 18 (12).

I'ved used pins 2, 6 and 12.

You'll see how mine is connected up in the image below.

![Unicorn HAT and Skywriter setup]({{ site.url }}/assets/unicorn_skywriter_setup.jpg)

Before you go any further, it's probably a good idea to test that your Unicorn
HAT and your Skywriter HAT are both still working properly by running one of 
the example scripts for both.
{'fraction_non_alphanumeric': 0.06653129479216435, 'fraction_numerical': 0.009555661729574774, 'mean_word_length': 3.8680232558139536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795522', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2608, 'n_words': 1320}