The Snap! Unicorn HAT Server allows Snap! blocks to manipulate a Unicorn HAT.
The Snap! blocks map to the Unicorn HAT API.
The server runs on a Raspberry Pi with an installed Unicorn HAT.
A full install of the Unicorn HAT software will install
python
and the required python packages: Unicorn HAT package
and flask. Answer y
to all the prompts.
cd
curl -sS https://get.pimoroni.com/unicornhat | bash
Verify that Unicorn HAT installation with:
$ cd ~/Pimoroni/unicornhat/examples/
$ sudo python ./simple.py
Install git
with:
$ sudo apt-get install git
Install the server with:
$ mkdir ~/git
$ cd ~/git
$ git clone https://github.com/athenian-robotics/snap-unicorn-hat.git
The server can run with python
or pypy
. Install pypy
and the required packages with:
$ sudo apt-get install pypy pypy-dev
$ curl https://bootstrap.pypa.io/get-pip.py | sudo pypy
$ sudo pypy -m pip install unicornhat flask
Execute the server using python
with:
$ cd ~/git/snap-unicorn-hat
$ sudo python ./server.py
Execute the server using pypy
with:
$ cd ~/git/snap-unicorn-hat
$ sudo pypy ./server.py
To install the Unicorn HAT blocks:
- Download the Snap!
block definitions
to the computer running your browser. You can copy and paste the definitions into a local file using an editor or use
wget
:
wget https://raw.githubusercontent.com/athenian-robotics/snap-unicorn-hat/master/snap/UnicornHatBlocks.xml
-
Start Snap! in your browser
-
Click on the page icon in the upper left hand corner of the Snap! window (the icon to the left of the cloud icon) and then click on
Import...
and choose the UnicornHatBlocks.xml file created in step #1.
-
Make sure that you can reach your Raspberry Pi from the machine running your browser using the
ping
command. -
Since block requires the Raspberry Pi hostname, it is best to create a variable and assign it the hostname and then use that variable reference in all your blocks accessing the Unicorn HAT.
-
Pixel changes will not be seen until
show
is called.