Skip to main content

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 ModelCAM0 Setting StatementCAM1 Setting Statement
    OV9281dtoverlay=ov9281,cam0dtoverlay=ov9281,cam1
    IMX290/IMX327dtoverlay=imx290,clock-frequency=37125000,cam0dtoverlay=imx290,clock-frequency=37125000,cam1
    IMX378dtoverlay=imx378,cam0dtoverlay=imx378,cam1
    IMX219dtoverlay=imx219,cam0dtoverlay=imx219,cam1
    IMX477dtoverlay=imx477,cam0dtoverlay=imx477,cam1
    IMX296dtoverlay=imx296,cam0dtoverlay=imx296,cam1
    IMX708dtoverlay=imx708,cam0dtoverlay=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,cam0
    dtoverlay=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 0
    rpicam-hello --camera 0 -t 0
    # Open camera 1
    rpicam-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