What is #CheerLights?
Cheerlights is a IoT based light control system, originally intended to allow social media to dictate the colour of festive lights around the world.
The current cheerlight status
How does it work?
Put the word Cheerlight and a colour in a tweet and you’ve just told light systems around the world the colour they should show. On the website is a list of the currently supported colours.
On the back-end there is a feed aggregator which exposes a JSON, TXT or XML API.
My plan was to use the Pimoroni Unicorn HAT to display the most recent 64 colours from the “Full” feed. Unfortunately I first started playing with this during my lunch hour at work….. where I didn’t have a Pi. So I wrote a console app in Python to read the JSON, output all the available colours, and then poll the “Last” feed for updates.
Time to put a HAT on
I wrote some code without the Unicorn HAT to hand then tested it when I got home (there weren’t too many bugs!). Rather than using the UnicornHAT Python module I chose to use the underlying ws2812 module. Madness you say? But no! The Unicorn HAT is just a matrix of NeoPixles which means any ws2812 device should “just work”. Up until now I could only control my 16 pixel NeoPixel from the Pi using a micro controller (read Arduino clone) as an interface. So I wired it up; the data line goes to GPIO18 (via a low value resistor to reduce risk of power spikes) and +ve to 3.3v, otherwise we’ll blow up the Pi! It worked as advertised first time – bonus.
In the code there is a maxPixels variable to allow you to limit the number of pixels you wish to light. The 64 NeoPixels on the UnicornHAT are wired in a left to right/right to left pattern so it goes
up to 64. So as the new colour is added the pattern shifts down in a “snake” like way.
The colours are translated to RGB values via a dictionary of the supported Cheerlight colours.
Let’s Get Festive
This section is UnicornHAT specific as the Python module allows you to treat the pixels as a grid, which makes it easier to draw patterns. It’s Christmas, and Cheerlights was devised for the festive season, so a tree is the obvious choice.
I ended up with three modes;
- 0 – All colours – the tree is a mosaic of the most recent colours with the most recent at the top
- 1 – Lights – five key co-ordinates (defined in a list) represent fairy lights or baubles on the tree. These are lit by the most recent colours, with the star on the top being the latest
- 2 – Star – only the most recent colour and this is the top most pixel
The tree patten is defined by as a list of pixel co-ordinates. The above pictures have some white paper over the pixels to diffuse the light which gives a nice effect.
Time for Turkey Curry?
Well, that’s that. I hope a few of you reading this have a play with the code, be it with generic NeoPixels or a Unicorn. Let me know how you get on in the comments below.