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)
-
Open the config.txt file (choose the correct path based on your system version):
sudo nano /boot/config.txt # For some older system versionssudo nano /boot/firmware/config.txt # For most newer system versions -
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:
dtoverlay=imx219,cam0 #CSI0 (MIPI0) -
To use only CSI1 (MIPI1), add the following line:
dtoverlay=imx219,cam1 #CSI1 (MIPI1) -
To use both CSI0 (MIPI0) and CSI1 (MIPI1) simultaneously, add both lines:
dtoverlay=imx219,cam0 #CSI0 (MIPI0)
dtoverlay=imx219,cam1 #CSI1 (MIPI1) -
After modification, reboot the Raspberry Pi to use the CSI interface with the camera:
sudo reboot
Camera Detection
- If the CSI interface is not enabled, enable it 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:
rpicam-hello --camera 0 -t 0 # Open camera number 0
rpicam-hello --camera 1 -t 0 # Open camera number 1 - If the camera is detected but fails to start, try updating the system:
sudo rpi-update
Display Real-time Preview
- If the CSI interface is not enabled, enable it 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
Take Photo
- If the CSI interface is not enabled, enable it 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
Video Recording
- If the CSI interface is not enabled, enable it 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