Official website for Linux User & Developer
FOLLOW US ON:
Oct
28

Pi Camera Quick Installation Guide

by Rob Zwetsloot

Setup your Raspberry Pi Camera fast with our with our quick tutorial, and then learn the basics of using it

One of the most recent Raspberry Pi accessories is the tiny Pi Camera board – a small PCB with a camera sensor mounted to it that connects to the Pi. It connects directly to the Raspberry Pi board to save USB slots, however this does not make it exactly plug and play, so you’ll need to do some extra set-up on your Raspberry Pi to get it to work.

The Pi Camera has multiple use cases, such as timelapse photography, using as a webcam or even as an optical sensor for a Pi-powered robot. As it doesn’t take up any USB ports and draws very low power, it can be a lot more versatile than a standard webcam.

The Pi Camera itself is not a low quality piece of kit either – with a 5MP sensor, it’s also able to create up to 1080p quality video, the same as the Raspberry Pi’s HDMI output. Grab your Raspbian SD card, and get started making the most out of your Pi Camera.

Raspberry Pi
Connect your Pi Camera with our quick guide

Resources

Raspberry Pi
Raspbian
Pi Camera from RS Components and element14
Ashton’s picam module

Step by Step

Step 01

Attach Camera

To attach the camera to the Raspberry Pi, locate the slot between the Ethernet and HDMI port, and gently lift up the fastener. Insert the ribbon of the camera board, making sure to align the ribbon’s connectors with those on the Raspberry Pi.

Step 02

Pi Preparation

Before we try and enable the Raspberry Pi camera, make sure your firmware and software are all up-to-date with a quick software upgrade. In Raspbian, we do this by opening the terminal and using:

$ sudo apt-get update

…followed by:

$ sudo apt-get upgrade

Step 03

Pi Config

Once that’s finished, run in the terminal or command line:

$ sudo raspi-config

…to start the standard configuration screen. Navigate down to Enable Camera, press Enter, and then simply key over to enable and confirm with another press of Enter. Select Finish, and reboot.

Step 04

Take Pictures

To take pictures with the Raspberry Pi Camera, you’ll simply need to enter:

$ raspistill -o image.png

This will show a five second preview of the input of the camera, and then capture the last frame of the video

Step 05

Record Video

To record a video, we use a similar command, raspivid, like so:

$ raspivid -o video.h264

Similar to the image taking,

Step 06

Picam

If you want to do a little more with the Pi Camera, there’s a simple python wrapper currently available called picam. You’ll need to install it first though, and we’ll use pip for that. Install pip with:

$ sudo apt-get install python-pip

…and then enter:

pip install https://github.com/ashtons/picam/zipball/master#egg=picam

Step 07

Picam Photos

We can now use Python to construct a script to take photos with the picam module. Very simply, all you need to do is enter:

import picam

i = picam.takePhoto()
i.save('/home/pi/test.jpg')

And running it will take photo, test.

Step 08

Advanced Photos

You can have it take photos of specific size and quality with a time-based name by editing the code to look like this:

import picam
import time

ii = picam.takePhotoWithDetails(640,480, 85) 

filename = "/tmp/picam-%s.jpg" % time.strftime("%Y%m%d-%H%M%S")

ii.save(filename)

Step 09

Picam Video and More

Picam also allows you to take video in a similar way to the above, with the main difference being that you’ll use recordVideo. You can use the code to take photos or video at regular interval for timelapse, or have it trigger during a specified event

  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.