What is it?
Yoda in Action
Following on from the Darth Beats Star Wars project, I decided to create another Star Wars related Raspberry Pi project. I was bought a Pimoroni inky pHAT and I also came across an old Lego Yoda alarm clock. It was too good to be true! Behold, "Yoda Tweets".
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.
To get started, attach the inky pHAT and then install the required program. simply type:
curl https://get.pimoroni.com/inkyphat | bash
Creating the Images
Now 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.
Displaying the Images
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.
Displaying the Text
Displaying 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. More details on how to set this up can be found here.
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)
Fixing up Yoda
The 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.
You can download the full code here:
Why not send Yoda a Tweet using @dan_aldred or the #StarWars hashtag, may the force be with you.