Camera

The are two main options for attaching a camera to the Pi.

  1. use a USB camera on one of the USB ports (make sure it is Linux compatible - most are)
  2. use a custom made Raspberry Pi camera connected to the Pi with a 15 ribbon cable

Option 1. requires no configuration and can be accessed as a
Video4Linux (V4L) device named ‘/dev/videoX’ discussed below.

Option 2 needs some more explanation

Custom Made Raspberry Pi Cameras

Connecting to the Pi

There are a number of custom made cameras for the Pi, e.g.:

They usually come with 15 ribbon cable that links the camera with Pi. The Pi has a special connector for this which is close to the Ethernet jack.

The ribbon cable is color coded because orientation matters. On the camera side the blue backing should face away from the PCB. On the Pi side the blue backing should face towards the Ethernet jack.

To insert the cable into the connectors: Gently pull up the latch covering the connector and ush it slightly to the side revealing a slot. Stick the ribbon cable into the slot and then push the latch down again locking the cable. Note, ribbon cables are available in many lengths: 60cm 100cm, 200cm

The Pi Zero supports the same cameras but a slightly different cable is required since the board connector (there is only one) is shorter.

Activation and Testing

First enable the camera with

$ sudo raspi-config

Interfacing options → P1 Camera

Then reboot and take a test picture with raspistill1 like so

$ raspistill  --verbose  -o test.jpg

You can also capture movies in different formats with raspivid, raspividyuv and raspiyuv2

picamera3, a specialized python library can be used to access the camera programatically.

Example:

import picamera

camera = picamera.PiCamera()
camera.capture('test.jpg')

Enabling V4L Support

If the tools mentioned in the previous section are sufficient for you this step is unnecessary. V4L enables additional tools and provides a more standardized API.

To enable V4L support use

$ sudo modprobe bcm2835-v4l2

This will only last until the next reboot. To make it permanent edit /etc/modules and add the line

bcm2835-v4l2

This should materialize a device named /dev/video0 which can be used with all the standard V4L tools.

Video4Linux (V4L)

The v4l-utils4 package provides a bunch of useful tool:

Examples:

# list devices
v4l2-ctl --list-devices

# list formats
v4l2-ctl --list-formats-ext

Other tools you might want to look into:

Python API

Python bindings can be install like so:

$ pip3 install pyv4l2

Example

TBD

  1. sudo apt install libraspberrypi-bin↩︎

  2. sudo apt install libraspberrypi-bin↩︎

  3. sudo apt install python3-picamera↩︎

  4. sudo apt install v4l-utils↩︎