Tested on:Raspberry Pi 2; Raspberry Pi B+; Python 2.7; Raspbian pre Jessie
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:Adafruit LCD plate

Joker – a Raspberry Pi joke telling machine using the Adafruit LCD plate

In this post, setting up a Raspberry Pi Joke telling machine based on the module pyjokes with the pretty Adafruit LCD plate as display is explained.

First, follow the detailed assembly instructions from Adafruit and mount the plate on the Raspberry Pi.

Install Pyjokes
Ben Nuttall, Alex Savio, Borja Ayerdi and Oier Etxaniz of the Pyjokes Society wrote Pyjokes, a comfy module which delivers programming jokes, thanks for that!
Install Pyjokes with

Setup I2C manually
The automated setup of I2C with raspi-config did not work like it should, so here is how to install I2C manually. Open modules with sudo nano /etc/modules and add

at the end of the file. Then, open config.txt with sudo nano /boot/config.txt and change the line


. Then, add at the end of the file the line

After rebooting the Raspberry Pi, test if the installation is good by entering

If I2C is running and the LCD display attached, this shows a device mounted at the address 20 like this:

I2C working

I2C working

Install Adafruit LCD drivers
Now, the drivers for the LCD plate need to be installed:

LCD plate usage
Two very important functions are clear for clearing the display and message for writing to it. message accepts '\n' for linebreaks:

Much more information about the LCD plate in the great CS Wiki from Michael Spivey.
Install Joker
Fetch and execute the script with

If the application should be executed automatically after booting, consider using a shell alias.

Code explained
The only tweak is converting the jokes to a format which fits the LCD display. This is done by splitting the joke into words, putting together sentences with a maximum length of 16 characters and adding a linebreak for every sentence:

Then, the joke is fed into the display with two lines per frame:

The complete script
Click on Full Script to show all of the code.

Joker telling a totally random joke

Adafruit LCD plate: https://www.adafruit.com/products/1115
Adafruit LCD plate assembly: https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/assembly
Pyjokes Society Website: http://pythonhosted.org/pyjokes/
Pyjokes on Github: https://github.com/pyjokes
Michael Spivey - LCD plate CS Wiki: http://spivey.oriel.ox.ac.uk/corner/Adafruit_LCD_plate_for_the_Raspberry_Pi
Shell alias tutorial: http://www.knight-of-pi.org/shell-alias-start-projects-on-the-raspberry-pi-after-booting/

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.


Time limit is exhausted. Please reload CAPTCHA.