CSI
This section introduces how to use the CSI interface function on the Raspberry Pi, laying the foundation for subsequent project development.
Note: A single camera can only be connected to MIPI0.
Note: The CSI interface is disabled by default and requires configuration in the config.txt file before use.
CSI Interface Selection - Driver Settings
-
Enable the CSI interface (disabled by default)
-
Edit the config.txt file
sudo nano /boot/firmware/config.txt -
Add the appropriate configuration to config.txt based on the camera model used (examples below use the imx219 driver for cameras):
Camera Driver Model CAM0 Setting Statement CAM1 Setting Statement OV9281 dtoverlay=ov9281,cam0 dtoverlay=ov9281,cam1 IMX290/IMX327 dtoverlay=imx290,clock-frequency=37125000,cam0 dtoverlay=imx290,clock-frequency=37125000,cam1 IMX378 dtoverlay=imx378,cam0 dtoverlay=imx378,cam1 IMX219 dtoverlay=imx219,cam0 dtoverlay=imx219,cam1 IMX477 dtoverlay=imx477,cam0 dtoverlay=imx477,cam1 IMX296 dtoverlay=imx296,cam0 dtoverlay=imx296,cam1 IMX708 dtoverlay=imx708,cam0 dtoverlay=imx708,cam1 -
To use only CSI0 (MIPI0), add the following line:
# CSI0 (MIPI0)dtoverlay=imx219,cam0 -
To use only CSI1 (MIPI1), add the following line:
# CSI1 (MIPI1)dtoverlay=imx219,cam1 -
To use both CSI0 (MIPI0) and CSI1 (MIPI1) simultaneously, add following lines:
# CSI0 (MIPI0) and CSI1 (MIPI1)dtoverlay=imx219,cam0dtoverlay=imx219,cam1 -
After modification, restart the Raspberry Pi to use the CSI interface to drive the camera normally:
sudo reboot
Camera Detection
- If the CSI interface is not enabled, enable the CSI interface first (Note: The driver settings must match the camera used)
- Use the following command to detect connected cameras:
rpicam-hello --list-cameras
- Open the corresponding camera:
# Open camera 0rpicam-hello --camera 0 -t 0# Open camera 1rpicam-hello --camera 1 -t 0
- If the camera is detected but fails to start, try updating the system:
sudo rpi-update
Displaying Real-time Preview
- If the CSI interface is not enabled, enable the CSI interface first (Note: The driver settings must match the camera used)
- Display the camera preview on the desktop (Note: This command cannot be used over an SSH connection):
rpicam-hello -t 0
Taking a Photo
- If the CSI interface is not enabled, enable the CSI interface first (Note: The driver settings must match the camera used)
- Take a photo and save it to the current directory:
rpicam-jpeg -o test.jpg
Recording a Video
- If the CSI interface is not enabled, enable the CSI interface first (Note: The driver settings must match the camera used)
- Record a 10-second video and save it to the current directory:
rpicam-vid -t 10s -o test.h264