TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Ras Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • LED Dance Suit
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
  • Random Hacks
    • Movile

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".

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.
  1. The inky pHAT will alert you to the incoming mention and then show you the tweet.
  2. If the tweet cannot be displayed then a 'loading' message is displayed.
  3. 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 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.

inkyphat.set_image(Image.open("MENTION.png"))
inkyphat.show()
inkyphat.clear()


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)
inkyphat.show()

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:
Picture
Why not send Yoda a Tweet using @dan_aldred or the #StarWars hashtag, may the force be with you.
Powered by Create your own unique website with customizable templates.