Instructables
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:


 
Remove these adsRemove these ads by Signing Up

Step 1: Setting up the New Pi with NOOBS


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


Step 2: Enabling WiFi with the Wi-Pi adapter and setting up VNC

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. 


Step 3: Running The QuoteMachine.py Python script

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?)

Step 4: Customizing The Quote Machine

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!
jatinbatra3 months ago

Nice one , I was also struck with same idea to create something called "words of wisdom" with Pi. But I would rather like to use C for programming Pi. I'm using WiringPi for GPIO control , can you plase tell me is it possible to replicate that with C. Thanks

is not usefull for jokes, i will give another use: like, things that i have to remember anyway, thanx

This is a really cool idea! I like the prospect of the joke machine. I had an idea for another function. I am thinking about taking your design and making a Fortune Cookie Machine. I found this little metal fortune cookie at a bookstore and I thought it would be cool to make a device like this and attach the metal cookie thing to it and make it generate fortunes. I have not worked with a Raspberry Pi yet, but I think this would be a really cool project to start working with it, when I can spare some cash to get supplies.

mazzmn (author)  The_Reverend12237 months ago
thx! I'd like to see what the fortunecookie looks like. The website I get jokes from also has fortunes. You could find a thermal printer and print them out! surplus stores sometimes have them as old credit card machines. use a model a pi to save some money and store the quotes on the sd card to reduce the need for the Wii pi csrd. Good luck!
Hardwired228 months ago
cool!!
mazzmn (author)  Hardwired228 months ago

Thanks!