I've had a Unicorn pHAT sitting in a box for a while, but I finally used it in a simple project. Because it has four rows of LEDs, I thought it would be ideal to make a binary clock from.
Let me show you how :)
This project can be tackled in two ways:
- an online version fetching time via NTP (network time protocol)
- an offline version using a RTC (real time clock)
In this instance, I'm focusing on the online version, though the offline version could be achieved as easily with an RTC shim such as the one pictured below, which can slide on the GPIO header between the Pi Zero and the Unicorn pHAT:
At the center of the project are a PiZero and a Unicorn pHAT. The PiZero fetches the time, converts it to binary and controls the Unicorn pHAT with a Python script. The Unicorn pHAT's RGB LED matrix can be used to display those binary values in any colour.
In order to have the Unicorn pHAT face forward, while still having the Pi Zero connectors at the back, an angled header was used.
The enclosure is a combination of acrylic and wood, except this time, the acrylic makes for the majority of the enclosure.
To form the acrylic in the desired shape, a small torch was used to heat it and have it bend 90 degrees. Once cooled off, it retains the new shape. Repeating this action two more times, the final shape is achieved. Careful not to put the torch too close to the acrylic to prevent it from burning or leaving marks!
To finish the enclosure, two wooden "end caps" were milled using the CNC and the edges rounded with a router, though a similar result could be achieved with a bandsaw and some manual sanding for example.
On the software side of things, I started off with the latest Raspbian Jessie Lite image from 23/09. Set up network connectivity via wifi by editing the "wpa-supplicant.conf" file.
Once network connectivity was set up, I proceeded with the upgrade of the software:
pi@binaryclock:~ $ sudo apt-get update && sudo apt-get upgrade -y
Don't forget to make sure the time is set to the correct zone:
pi@binaryclock:~ $ sudo cp /usr/share/zoneinfo/Europe/Brussels /etc/localtime
Installing the software to control the Unicorn pHAT and its dependencies, is a breeze as always thanks to Pimoroni's installation wizard:
pi@binaryclock:~ $ curl -sS get.pimoroni.com/unicornhat | bash
I chose a full install, including examples, though they are not required for this project. To know more about the installer, head over to the Unicorn HAT GitHub page.
For the binary clock, I created s mall script which takes the time, converts it to binary format and lights up the correct LEDs on the Unicorn pHAT. A cronjob ensures the script is started at boot time.
Here's the full script:
Make sure the downloaded script is executable:
pi@binaryclock:~ $ sudo chmod +x binary.py
Finally, add the cron job:
pi@binaryclock:~ $ sudo crontab -e ... # m h dom mon dow command @reboot sudo /home/pi/binary.py
Upon reboot, you should see the LEDs light up on the Unicorn pHAT!
You are of course free to change the colours for both the time and the background:
Hope you liked this project, let me know in the comments!