The are two main options for attaching a camera to the Pi.
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
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.
First enable the camera with
$ sudo raspi-config
Interfacing options → P1 Camera
Then reboot and take a test picture with raspistill
1 like so
$ raspistill --verbose -o test.jpg
You can also capture movies in different formats with raspivid
, raspividyuv
and raspiyuv
2
picamera3, a specialized python library can be used to access the camera programatically.
Example:
import picamera
camera = picamera.PiCamera()
camera.capture('test.jpg')
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.
The v4l-utils
4 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 bindings can be install like so:
$ pip3 install pyv4l2
Example
TBD