The Raspberry Pi Powered Joke Machine

by mazzmn in Circuits > Raspberry Pi

23487 Views, 166 Favorites, 0 Comments

The Raspberry Pi Powered Joke Machine

IMG_2932.JPG
I recently received a new Raspberry Pi and wanted to create an Intro to Raspberry Pi project. My Pi included a 16x2 LCD display and a Wi-Pi Card so I created the Wireless Raspberry Pi Powered Joke Machine. Just press the push-buttons and the machine will look up a one-liner and scroll through it. (Admission of guilt here...I originally thought it would be neat to create a desk-toy that could display inspiring and educational famous quotes...the Joke Machine can do this, but when I found I could just as easily generate one-liners, I decided that would be more fun :-) )

This Step by Step Instructable walks you through the process of setting up a new Raspberry Pi, adding the the PiFace Control and Display LCD, the WiPi wireless and the provided python script TheQuoteMachine.py which looks up jokes and quotes on a free service called iheartquotes.com. it'll also describe how to access your Pi without need for a keyboard or Display using VNC remote access.

Parts Needed
  • Raspberry Pi model B
  • 8G SD Card with NOOBS installed
  • Pi micro-usb cable and adapter
  • WiPi wifi adapter (or ethernet cable)
  • PiFace Control and Display - LCD Display which includes 7 buttons and an IR chip
  • During setup you'll want a USB keyboard, an HDMI cable and Monitor
  • Project box - I had an old watch gift box laying around 
Tools needed
  • Tin snips to cut slots in project box
  • Dremel style tool to cut a hole for the LCD display and smooth sharp edges
  • Label maker
  • Sharpie to mark the project box
  • Vinyl tape

Here's a Video of the Joke Machine in action:


Setting Up the New Pi With NOOBS

PiIMG_2784.JPG
20140119_205520.jpg

A Raspberry Pi comes with "Do it Yourself Filling", that is you decide what flavor of Linux you want on it. An easy way to do this is to use a NOOBS SD card to install Linux 

NOOBS stands for New Out of the Box Software. You can buy a pre-installed NOOBS SD card (what I used for this project) or download your own from http://www.raspberrypi.org/downloads.
I connected an HDMI cable, power adapter and USB keyboard (no ethernet is needed for NOOBS) When NOOBS boots up, I was presented with the following options to install:
  • Archlinux - a configurable linux distro not recommended for newbies
  • OpenELEC - Open Embedded Linux Entertainment Center (OpenELEC) a small Linux distribution meant to be a media Center
  • Pidora - Pidora is a Fedora Remix optimized for the Raspberry Pi computer
  • RaspBMC - the XBOX Media Center interface
  • Raspbian (Recommended) Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware
  • RiscOS - RISC OS is a British operating system designed specifically for the ARM processor

I picked the recommended Raspbian flavor of Linux

After the formatting finished I used the configuration screen to:
  • Change from the default ID and password of pi / raspberry
  • Enabled ssh from the advanced options (more about SSH later)
Next I ran the startx command to bring up the graphical desktop


Enabling WiFi With the Wi-Pi Adapter and Setting Up VNC

WiPiIMG_2786.JPG
20140120_194051.jpg
vncviewer.jpg
Configuring the Wireless Network
I followed these instructions to configure the wireless network using commandline instructions.

Basically the steps are to:
  • sudo nano /etc/network/interfaces
  • fill in wpa-ssid "ssid" and  wpa-psk "password"
  • reboot
The Wi-Pi works great, and it gives off a nice blue glow when it is communicating.
After the reboot, a connection was made to my network and I was able to surf the internet from the Pi.
I also used Winscp to connect from my Windows 7 box to the Pi, more about that next.

Using your Pi without a dedicated monitor and keyboard via VNC
Next I set up VNC so that I could access my Pi from my normal laptop computer. Vnc is a process that allows me to use Graphical applications without connecting any screen up to the Pi itself.  Here's how to set it up
  • Install vncserver by running this command on the Pi:
    sudo apt-get  install tightvncserver
  • start the vnc server by running the command (the first time you run it it will ask you to create a vnc password)
    vncserver
  • download vncviewer for your laptop (or desktop) computer
  • connect from your laptop using the ipaddress and port of the vncserver (and the password you created above)
To use vnc when you don't have a Monitor on the Pi, you can either set up the Pi so vncserver starts automatically at boot time, or connect to the pi by using ssh or winscp to log on commandline style to the Pi and start the server. 


Running the QuoteMachine.py Python Script

IMG_2930.JPG
IMG_2924.JPG
TheQuoteMachine.py is written in Python
Python is already installed on the Raspberry Pi, so to run my Quote Machine script you simply need to
  • Download the script from instructables.com (to your Raspberry Pi)
  • Create a bin directory to store your favorite scripts 
    mkdir /home/pi/bin
  • copy TheQuoteMachine.py to /home/pi/bin  
  • make it executable by running the command
    chmod +x /home/pi/bin/TheQuoteMachine.py
Install the PiFace Control And Display Example code
The PiFace Control and Display LCD screen comes with some example code that we need. You can install it by running the following command 
sudo apt-get install python{,3}-pifacecad

Install PyCurl
TheQuoteMachine.py uses Pycurl to call off to the web and get a random quote.
To install curl run the following command: 
sudo apt-get install python-pycurl

Push a Button, Get a Joke
Now you can run /home/pi/bin/TheQuoteMachine.py  It will connect to the free service http://www.iheartquotes.com and display hilarious one-liners. It does this by running a URL that returns the one-liners back in straight text, splitting the text up into 16 character wide segments and then monitoring the PiFace button events that let you scroll up and down through those segments.

The Quote Machine Buttons:
  • Button 1 is the back button
  • Button 2 is the advance display button
  • Button 3 is the New Quote button
  • Button 4 is the Quit Button
Install Your Quote Machine in a Project Box - steps vary depending on the box you use
  • I used a Sharpie to mark where the LCD display should be mounted on the project box
  • I used a Tin Snips to cut slots in the edge of the project box to make room for the buttons and the power adapter
  • I used a Dremel style tool to cut a hole in the lid of the box (and to smooth out sharp edges)
  • Finally a little tape to cover sharp edges
  • and a label machine to label the machine (is that redundant or ironic?)

Customizing the Quote Machine

IMG_2933.JPG
Quotes Instead of Jokes
If you'd like to get Famous Quotes (there are many varieties available here)  instead of One-Liners out of the Joke Machine, make two simple changes to TheQuoteMachine.py
  • Change the "source" used on this line:
    c.setopt(c.URL, 'http://iheartquotes.com/api/v1/random?source=oneliners')
  • Replace the source name this line
    lineout = re.sub(r'\[oneliners.*','',lineout)

Run The Quote Machine at startup time:
To have the QuoteMachine.py script run automatically at startup, there are several ways you can do it, but the following works well
  • download the file "quoteStart" from this instructable. quoteStart calls TheQuoteMachine.py
  • copy it to /etc/init.d
  • run the following to make it executable
  • chmod +x /etc/init.d/quoteStart
  • test running the script to ensure it won't have problems at reboot time
  • register the command to run at startup by running the command:
  • sudo update-rc.d quoteStart defaults
Humor:  One comment about humor, when my sister noticed I posted this invention on Facebook, she was a little concerned..."this could be bad!!!" I think was her comment...but she was less worried when I assured her the jokes generated by the Joke Machine are not my jokes ;-)

Thanks for checking out my Instructable, I hope you have fun building your own Joke Machine.
Good luck on all your projects!