The first three
lines should seem
familiar to you
(from the camera
tutorial earlier).
This program
additionally
includes importing
modules that
allow us to access
and use the GPIO
pins.
FIGURE 21. The cardboard camera stick. FIGURE 22. The pulley on the camera stick.
volts). Most of the remaining pins (such as GPIO02 or
GPIO18) are ones you can use to output or read input in
the form of electricity. The pins labeled “Ground” provide
a return path for the electrical current. Numbering of the
pins is done in the same fashion you read text in a book —
left to right before moving down. You already have the
code for capturing stills with the camera module. Let’s
walk through how to set up the circuit and program.
The next few
lines simply set up
and define some
of the
components that
the program will
be using.
buttonPin = 7,
count = 0, and buttonPress = True define variables;
specifically, the number of the pin we are using to read
input, how many stills you’ll take, and the state of the
button (whether it’s being pressed or not).
GPIO.setmode( GPIO.BOARD) and
GPIO.setup(buttonPin, GPIO.IN, pull_up_down =
Refer to Figure 19 and Figure 20 for the circuit. This is
about as simple as it gets with the top wire connected to
pin 6 and the bottom wire connected to pin 7.
GPIO.PUD_UP) prepare the pins for use. The most
important part here is that pin 7 is being coded to read
input. You’ve seen camera = PiCamera() before.
Here are the basics of the program that we will use.
Note that the program allows you to take one still
photograph which it saves to the Pi desktop (see
Resources). Let’s walk through it quickly so that you have
an intuitive understanding of its contents:
import RPi.GPIO as GPIO
from picamera import PiCamera
from time import sleep
buttonPin = 7
buttonPress = True
count = 0
GPIO.setmode(GPIO.BOARD)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down
= GPIO.PUD_UP)
camera = PiCamera()
while count < 1:
buttonPress = GPIO.input(buttonPin)
if buttonPress == False:
camera.capture(“/home/pi/Desktop/picture.jpg”
count += 1
FIGURE 23. The camera stick
base.
FIGURE 24. The
camera module at the
top of the stick.
68 May/June 2018