Getting Started
So in this hack, Python is used to collect the tweets from your timeline. Python code searches for a keyword or your handle and then returns these tweets to the program. Depending on what the tweet contains, one of three events will happen.The inky pHAT will alert you to the incoming mention and then show you the tweet.If the tweet cannot be displayed then a 'loading' message is displayed.If any messages contain the hashtag #StarWars then a special R2D2 image is displayed before the main tweet.To get started, attach the inky pHAT and then install the required program. simply type:
curl https://get.pimoroni.com/inkyphat | bash
Creating the ImagesNow to create your images for the inky pHAT display. This project uses three, but you can add more if you have more 'search terms' or triggers. You can use most graphics editing software however on the Pi you can install GIMP.
sudo apt-get install gimp
Open a new file and set the size to 212 x 104, then create your image. Remember that you only have the three colors, black, white and red.
Once you have created you required images, saved them into the same folder as the program and use the code to open and write them to the inky pHAT display.
inkyphat.set_image(Image.open("MENTION.png"))
inkyphat.show()
inkyphat.clear()
Displaying the TextDisplaying the text string from the tweet is also simple. Take the message content and store it in a variable. Then wrap the text so that it is nice and neatly displayed in the inky pHAT. Then choose a colour and write the text to the screen. In order to pull down your tweets you will need to install Tweepy
sudo pip3 install tweepy
and have the required authentication keys.
message = tweet_to_check
txt = textwrap.fill(message, 31)
w, h = inkyphat._draw.multiline_textsize(txt, font)
x = (inkyphat.WIDTH / 2) - (w / 2)
y = (inkyphat.HEIGHT / 2) - (h / 2)
inkyphat._draw.multiline_text((x, y), txt, inkyphat.BLACK, font)
inkyphat.show()
Fixing up YodaThe final part of the project is to embed a Pi Zero and the inky pHAT into Yoda! Getting inside the Yoda clock case was very tricky, the Force was strong with this one, but.... Fit it all back together and add a USB lead for plugging in from one of the buttons holes at the back. Set the program code to run automatically ion boot up and there you go, you own Yoda Tweets. Sit back and enjoy the show.
Why not send Yoda a tweet using @dan_aldred
or the #StarWars hashtag, may the force be with you.
Comments