PaPiRus Inspirational E Ink Twitter Display
This is a quick and easy project to show you how you can utilise the functionality of the PaPiRus display HAT to display inspirational tweets to keep you motivated throughout the day. The project gets the top 20 tweets from twitter handle @quote_motiv and display them one at a time, using the buttons to scroll up and down to the next or previous tweet. Pretty cool eh? Moreover the code can be adapted and tweaked to automatically display a new tweet every 60 seconds or so or even display a tweet from someone else by using the search function.
What you will need
- Raspberry Pi Board
- PaPiRus Display HAT
- PaPiRus Case
- Power Supply
- microSD card
- Mouse & Keyboard (initial setup)
- Ethernet cable (optional)
Getting Started
The first thing you will need to do is download the latest Raspbian operating system, which you can download on the Raspberry Pi website. For this project you can either use Raspbian Desktop or Raspbian Lite version.
Once you have booted your Raspberry Pi you will need to connect to your internet so you can download an grab the latest software required. You can either connect to your Wi-Fi or plug in an Ethernet cable from your router/switch. Once connected you first need to run an update to ensure everything is up-to-date. Open up a Terminal window or from the command line type in the following:
sudo apt-get update
Now we can go ahead and install the PaPiRus software:
curl -sSL https://pisupp.ly/papiruscode | sudo bash
Once installed and selected the PaPiRus screen size then it will reboot the Raspberry Pi. Once rebooted you can test the PaPiRus display to ensure everything install ok and that there are no issues:
papirus-test
If all is ok then you can now download the project python script.
wget https://raw.githubusercontent.com/PiSupply/PaPiRus/master/projects/twitter_feed.py
Now before we run the python script there are a few things we need to do before hand. The code itself relies on the twitter python library so you will need to install that using pip:
pip install python-twitter
Note: If you do not have pip installed you can install it with – sudo apt get install python-pip
Now there are a few things you need to do in order to use the twitter API. We need to create an application within the Twitter dev webpage, which is linked to your account. Once created you will then receive tokens which are unique to your account. These tokens are then used to access your twitter account.
Over on Twitter’s development site, you need to “Create an app” and give it a few details. They want to know a little about what you’re doing so fill in details as needed. We also really only need “Read” permission.
The important things that we need from here are details of the tokens. These need to kept secret, so don’t post them anywhere! Someone might use them to post as you if you’re not careful.
There are four long alphanumeric strings you need:
- Consumer API key
- Consumer API secret key
- Access token
- Access secret token
Save these somewhere safe, as you will need them in your Python code.
Now lets edit the python script and add our Twitter keys and tokens to allow access to your Twitter feed:
sudo nano twitter_feed.py
Edit the following lines and add your details:
consumer_key = '*******************' consumer_secret = '*******************' access_token_key = '********************' access_token_secret = '*******************'
Save the changes and exit:
CTRL+O then ENTER to save, CTRL+X to exit.
Now you can run the python script to display your tweets:
sudo python twitter_feed.py
You should see the first tweet displayed on the PaPiRus display. Now you can use the buttons at the top of the PaPiRus display to scroll through the rest of the tweets from your feed. SW4 button will scroll down to the next tweet and SW3 will scroll back up to the latest tweet. The script will collect the top 20 tweets on the feed and then allow you to scroll through. If you wanted to refresh and get the latest tweets then you can press the SW1 buttons which will refresh the feed.