In the previous posts (Parts I, II and III) I discussed setting up the Raspberry Pi and camera, taking and compiling photos to make a photostrip, and automatically uploading pictures to Flickr. In this post we deal with hardware. The input/output for the photo booth should be exceptionally simple: a light will indicate that the photo booth is ready to take pictures and a single button will start taking pictures.
The Raspberry Pi basic input/output easy through the GPIO pins on the Pi’s board. I found the following tutorials very helpful: Morse Code on an LED and Buttons and Switches. Using these tutorials as a guide, I found that the following circuit should allow all of the functionality the photo booth requires:
Here is what the test circuit looks like in real life:
In order to get the circuit to communicate with the Pi, I used the GPIO library for Python included in the Pi’s operating system. Here is a snippet of code that will wait for the button to be pressed, then flash the LED and take a picture
import time import RPi.GPIO as GPIO from subprocess import call # set input/output pins out_pin = 4 in_pin = 17 # wait time parameters pause_time = 0.5 bounce_time = 0.05 # setup GPIO pins GPIO.setmode(GPIO.BCM) GPIO.setup(out_pin, GPIO.OUT) GPIO.setup(in_pin, GPIO.IN) # take pictures -- this will be more elaborate later def take_pictures(): call(["raspistill", "--timeout", "1000", "--output", "pic1.jpg"]) # wait for button press, flash light, and take a picture prev_input = 0 while True: input = GPIO.input(in_pin) if ((not prev_input) and input): print("Button Pressed") GPIO.output(out_pin, GPIO.HIGH) time.sleep(pause_time) GPIO.output(out_pin, GPIO.LOW) take_pictures() break prev_input = input time.sleep(bounce_time) GPIO.cleanup()
Everything worked with the circuit on the breadboard, so I decided to solder the circuit onto a small perf board. The end result turned out looking much nicer despite my rather crude soldering.
In the next (and final) installment, I will put all of the code together for a fully functional photo booth. Hopefully I will have time to make a pretty box to house it.