could have been done with the camera
module, but this was the best looking way
to do it.
The time module is used to control
timing on execution and to provide unique
names for all of the photos based on the
date and time they were snapped. (Time
stamps are a great way to ensure unique
file names — as long as your clock is right!)
Raspberry Pi provides the GPIO library that
lets us toggle and read pins for the buttons
and LEDs. The Pi camera module controls
We start the live preview and do the
photo captures with it. The sys and OS
modules handle housekeeping tasks like
cleanly exiting the program, shutting down
the Pi, and working with the file system. To
make things a little more fun, we use the
Twython module to tweet the photos, and
the random module to let us select a
random set of Tweet text to go with the
To start your photo booth, just run
“sudo python photobooth.py” at the
terminal. After a few seconds, your camera
preview will appear. If it’s flipped, just exit
the program (ESC key or Control C) and
adjust the hflip or vflip settings in the code.
Now, press the trigger button. The photo
booth will turn on the power switch, do the
countdown, take your photo, repeat three
times, then turn the power switch off.
Make some faces and have fun, then
exit the program. Your photos will be in the
/home/pi/photobooth_photos directory and
should be posted on Twitter if you have that
enabled. If something went wrong, the error
messages will point you to what part of the
setup is incomplete.
Once you’re happy with how things are
working, we need to set up the Pi to start
up the photo booth program by default. We
don’t want to connect a keyboard at every
startup. Remember that easy setup was a requirement. We
need the Pi to automatically log in and then start the
At a terminal, open the inittab file with your favorite
editor (i.e., “sudo nano /etc/inittab”). Find the line that
reads “1:2345:respawn:/sbin/getty 115200 tty1” and put
a “#” at the beginning of the line to comment it out.
Directly under it, type “1:2345:respawn:/bin/login -f pi
tty1 </dev/tty1 >/dev/tty1 2>&1.” Press Control+o to save
the changes and Control+x to close the editor.
Now, we’ll tell the Pi to run our program in the shell
March 2016 31
Repository for PiBooth
Twitter — The Art of Command Line
■ FIGURE 5. Careful removal of a viewfinder glass allowed me to
mount an LED inside the camera and use the existing optics as an
updated light pipe.