5 months ago

Get Started with the Pi Camera

In this Raspberry Pi 101, snap photos from your Raspberry Pi using its special, programmable camera

The Raspberry Pi has a few mysterious connectors on it that you wouldn’t normally use when hooking it up. We’ve covered the GPIO pins in a previous issue, but now we’re going to move onto the CSI port. You’ll find this located between the HDMI and audio jack on a normal Pi, and on the edge of a Pi Zero. CSI stands for Camera Serial Interface and, as the name suggests, it’s used to connect a camera to the Raspberry Pi. Not just any camera either: specifically, the Raspberry Pi Camera Module.

The Camera Module, so called because it looks like a piece of circuit board and is attached via a ribbon cable, is a special programmable camera for the Raspberry Pi. It can take photos and video, and has many extra functions like time-lapse photography and slow-motion recording. It’s fairly easy to control from the command line, or by using specific code in a Python script.

With the recent addition of a camera port to the Pi Zero, every Raspberry Pi can use the camera for some cool and fun projects. Here’s how to get started with it.

You’ll need

Raspberry Pi
Raspbian
Pi Camera Module

STEP-01 Attach the camera

With the Pi turned off, gently lift up the plastic catch of the CSI connector. Take the end of the ribbon and insert it into the slot, with the silver connectors facing towards the HDMI port, before pushing the catch firmly back down.

Step 1. The white vertical strip is part of the connector

Step 1. The white vertical strip is part of the connector

STEP-02 Enable the camera

Boot up the Raspberry Pi. Once you’re in the desktop environment, head to Menu > Preferences and select Raspberry Pi Configuration. Go to the Interfaces tab and click the option to enable the camera.

STEP-03 Taking a photo

You can take a photo from the terminal by typing raspistill -o image.jpg. This will show a preview for five seconds, then shoot an image at maximum resolution and save it as image.jpg by default.

STEP-04 Recording video

Video is a little more complex: you need to tell it how long the video is in milliseconds. For ten seconds, use raspivideo -t 10000 -o video.h264. It’ll preview what you’re shooting, and the file will be at 720p.

STEP-05 Python programming

Controlling the camera with Python is easy: all you need to do is import the picamera module at the beginning of your script. There’s some info on how it works online.

STEP-06 Pi Zero

The updated Raspberry Pi Zero adds a special connector to attach the camera. You’ll need to get an adapter cable to plug it in (magpi.cc/2gT2KwE), but otherwise it works the same.