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)

  • Open the config.txt file (choose the correct path based on your system version):

    sudo nano /boot/config.txt            # For some older system versions
    sudo 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 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:

    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