Creating a Twitter Follower Counter with Pimoroni Scroll Bot & Raspberry Pi Zero
Pimironi Scroll Bot Tutorial
This is a tutorial for soldering, assembling and coding the scrolling notification kit, also known as the Pimoroni Scroll Bot. We’ll be putting the bot together, soldering the parts we need to and then coding it up with a simple python script to show the number of twitter followers we have.
TLDR: Let’s cut to the video
This video shows how to build the kit and to code it so if you don’t want to listen to my nonsense then just watch the video and I hope it gives you everything you need to build and code this beautiful little kit from Pimoroni.
Why though?
Covid-19 and various governmental lockdowns have been a bitch for everyone. A necessary evil but a real chore nonetheless and like many of us it will have left us pondering our existence.
During that pondering, I decided that as a father of two wonderful boys and a member of a wonderful community, I should teach kids in my neighbourhood to code and so I signed up to Code Club and have started a new club in my community.
Obviously at the present time here in the UK we’re in the midst of our third national lockdown and so the club isn’t really going to be doing a lot for the next few months and so I decided the best thing I could do is get myself up to speed by teaching my eldest son (Teddy aged 7) to code. The best way to teach a kid to code? Obviously it’s with Raspberry Pi.
Even better than doing it just with a Raspberry Pi would be to do it with one which makes use of the GPIO and allows you to view data and content in a cool way (like a 17x7 LED display).
The Pimoroni Scroll Bot Raspberry Pi Project Kit
This kit is lovely. It takes about 30 minutes for an adult to construct with a soldering iron and contains:
Raspberry Pi Zero W
Pimoroni Scroll pHAT HD
Mini HDMI to HDMI adaptor
USB microB to A adaptor
2x20 male GPIO pin header
Scroll Bot stand
Some lovely stickers
The only things you’ll need to add are a microSD card, a 2A microB USB power supply and a keyboard and mouse for first setup.
Assembling the kit
There’s nothing in my video that the assembly instructions from Pimoroni doesn’t already cover however as a noob when it comes to both Linux (or Raspberry Pi OS) and soldering I just thought I’d point out a few Gotchas:
When fitting the GPIO header to the Pimoroni Scroll pHAT HD make sure to solder it on to the back so the LED’s are on the opposite side to the female pin board.
When soldering on the 2x20n male GPIO pin header to the Raspberry Pi Zero W ensure that the short pins go through the top of the board and the long pins remain prominent to plug into the GPIO female socket of the pHAT.
When fitting the legs ensure the leg slots into the receiving slot at the highest point of the receiving slot rather than the lowest point, that way it can’t slip out of the back of the faceplate when secured with the bolts.
Creating the code
In order to run the code we first need to ensure we have the libraries we need. Open a terminal on the Raspberry Pi and install the Scroll pHAT HD Python library:
With that done you might want to follow the steps I did in the video to check you soldering is up to scratch but if you’re better at soldering than I am (highly likely) then jump straight into installing the Tweepy library.
Create a new python file and in it’s parent folder run the following:
You’ll need a set of credentials for the twitter API so if you haven’t already, sign up for an account in the Twitter developer portal and create a new application and authenticate using your credentials within the portal. With those details create a new python script named credentials.py and fill out the following values, replacing the placeholders with your actual values:
The code itself isn’t massive and normally I’d post it to GitHub but the script is so short, I’ve posted it in it’s entirety below:
What the code does is essentially loop every 0.05 seconds and show a message on screen. After a timeout of 500 seconds ( 8 minutes or so) the code gets the number of followers and sets an arbitrary message with the value which is then written to the hat using the scrollphathd library and then scrolled.
Save this script alongside your credentials.py and run on startup.
Running a script on startup
You obviously want your new Scroll Bot to run headless (without a keyboard or monitor) and you want your script to run as soon as the Pi Zero starts. The best way to do this is by creating a boot script and adding it to your crontab. There’s an excellent article on instructables for launching a python script on startup which would work brilliantly for your new twitter followers script.