The first two lines are importing functions from
external modules, i.e., they are bringing in capabilities
from other Python programs so that we may use
these functions in the camera program we are
creating. This saves us time and shortens the
code we have to write.
The next line — camera = PiCamera() — is
assigning a name to the PiCamera function that
will be used to refer to this function. It’s similar to
how one might refer to “Light Amplification by
Stimulated Emission of Radiation” as simply
“laser” in the sense that we are only assigning a
name for the sake of simplification. The lines
camera.start_preview() and camera.stop_preview()
are functions that turn the camera on and off for
you to get a preview of what you are capturing.
These are functions that came from the PiCamera
function you imported earlier. The line in
between — sleep( 10) — tells the camera to wait
10 seconds before executing the next line of
code. Again, this was a function you imported
from the time module at the beginning of the program.
Hopefully, this brief explanation gave a bit more
insight into the workings of the code and also showed
how friendly it can be to interpret and write Python.
One more thing I’ll add that the tutorial did not
include. This camera setup is pretty straightforward and
should work without a hitch due to its relative simplicity.
In most cases, if you believe you’ve done everything
correctly, any problems encountered are simple fixes.
So, if you run into any problems when you’re trying to
capture a still, try the following:
Pi 3 GPIO
supplementary explanations may provide some benefit.
Next is the first code you are instructed to enter into a
Python file to run for the camera. Let’s quickly run through
from picamera import PiCamera
from time import sleep
camera = PiCamera()
• Make sure you inserted the ribbon cable properly on
both the Pi and the camera. This includes ensuring that
the cable is pushed in all the way.
• Some people believe it’s better to insert all the
peripherals before you boot your Raspberry Pi.
• Make sure the power supply is sufficient (the
red LED is steady), and the Pi is reading the
SD card properly (the green LED blinks
• If it’s a power issue, try using a different
power source; if it’s the SD card, try
rewriting it or using a different one.
• Make sure that your Raspberry Pi is updated.
The commands for updating and upgrading
your Pi are sudo apt-get update followed by
sudo apt-get upgrade. (See Extra/Commands
• Updating your Pi is a good habit to get
into regardless of whether or not you’re
running into problems.
• Try rebooting your Pi.
FIGURE 19. Connecting the pushbutton to the Pi.
• This can do the trick sometimes, and you
may even decide to just come back to the
Pi later in the day.
66 May/June 2018