Cheerlights Pico Bot
Cheerlights is a really cool project connecting people around the world with synchronized lights. I wanted to make it easy for my kids set the color and not just watch the colors change so here’s a quick how-to along with some open source code.
You Will Need
- Raspberry Pi Pico W (make sure you get the Wifi-enabled version)
- 40-pin headers soldered onto the Pico
- Pimoroni Pico RGB Keypad
- Twitter developer account (free)
- IFTTT account (free)
- Source Code
I got the Pico W and the RGB Keyboard from DigiKey in the US.
Keeping it Simple
If you just want to display the color and not worry about doing a bunch of setup to enable color setting, you can just run the code and the buttons will look pretty but not do anything when pressed. Still looks great! There’s also a limit of 25 tweets per day (200 if you use a paid IFFT plan). It’s still worth it to see it in action but using Discord is a good alternative.
If This Then That then Twitter
Because the Pico microcontroller runs micropython, it doesn’t have support for OAuth, which you need to communicate directly with the Twitter API. As a workaround, you can use the IFTTT service to connect to Twitter. This guide covers how the general process works. We’ll customize it for our needs:
The “Tweet text” is very important. It needs to have “#cheerlights” exactly or the Cheerlights Project won’t be able to pick it up. It needs “{{Value1}}” so we can pass the specific color we want. Finally, it needs “{{OccurredAt}}” at the end so that Twitter doesn’t treat our tweets as spam and block the tweets.
To get your very own IFTTT API Key, make sure you’re signed in to IFTTT and go here:
Click on “Documentation” and you should see a page with your key:
You’ll need to add this to the source code.
Load ’em Up
First things first, you’ll need to load the latest Pimoroni image (tested on 1.19.9) onto your Pico. Next, install the “micropython-urequest” library. Finally, Grab the source code and use Thonny to copy all the files to your Pico. You will need edit the WIFI_CONFIG file with your details and also edit the main.py
file with your IFTTT key. If you have it plugged into your computer you can run the code directly from Thonny and see debug output.
What’s it Doing?
First the Bot connects to your WiFi network and lights up half the LED buttons with the colors that you can set. The other half are set to white. Then it hits the Cheerlights API and gets the current color, displaying it on half the LEDs. Every two minutes, it will connect to the internet and check for color updates. In between, if you press one of the color buttons, the Bot will use IFTTT to tweet your color and after 10 seconds, you should see the color update locally. A fun thing to do is to press a color button while watching the live stream on Twitch.
Is it Worth it?
Admittedly, it’s not the simplest project to setup. However, if you have some experience with the Raspberry Pi Pico (W) already, I highly recommend getting an RGB Keypad and trying it out. There’s just something really satisfying about having the power of connecting to thousands of people around the world at the literal press of a button.
Troubleshooting
- Color doesn’t change when I press the button
Twitter + IFTTT limits the free account to 25 tweets per day. If you have a Pro/Pro+ IFTTT account the limit is 200. On IFTTT you can look at the activity for your “applet” to see if the signal is even reaching the service - No lights! Nothing!
The Bot probably couldn’t connect to your WiFi network. Make sure the WIFI_CONFIG has all your details and has been uploaded to the Pico W. Or you hit the limit. You can see details on IFTTT and also your Twitter account’s profile page. - Debugging
You can usecurl
to test the signal to IFTTT manually. Details on the documentation page linked from here. Note that we’re usinghttp
vshttps
to keep things simple. - Still need help?
Indeed I threw this together quickly so hit me up on Twitter at @mankindforward for help and feedback