Template: CM4-DUAL-CAMERA-BASE Guide

From Waveshare Wiki
Jump to: navigation, search

Writing Image

USB2.0

To reduce consumption, USB interfaces are disabled in CM4 by default. If you need to use USB ports, please add the following line to config.txt file.

dtoverlay=dwc2,dr_mode=host

Then reboot the CM4. If you use the newest Bullseye image, the USB2.0 is set to OTG mode by default, and it occurs the error in CM4:

config failed, hub doesn't have any ports! (err -19)

To remove the errors, you can remove the line otg_mode=1 from config.txt file and add the line:

dtoverlay=dwc2,dr_mode=host

CSI

CSI and DSI are disabled by default. When using the camera and DSI, it will occupy three I2C devices: I2C-10, I2C-11, and I2C-0.

  • Open a terminal and run the following commands:
wget https://www.waveshare.net/w/upload/7/75/CM4_dt_blob_Source.zip
 unzip -o  CM4_dt_blob_Source.zip -d ./CM4_dt_blob_Source
 sudo chmod 777 -R CM4_dt_blob_Source
 cd CM4_dt_blob_Source/
 sudo  dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob-disp0-double_cam.dts

Recording test

And then connect the cameras and DSI display
1: Please power off the IO Board first before your connection.
2: Connect the power adapter after connecting the cameras and DSI display
3: Wait a few seconds before the screen boot up.
4: If the DSI LCD cannot display, please check if you have added /boot/dt-blob.bin. If there already has the dt-blob.bin, just try to reboot.
5: The camera needs to be enabled by raspi-config, enter sudo raspi-config on the terminal, choose Interfacing Options->Camera->Yes->Finish-Yes and reboot the system

Old Version (Buster)

  • Test the Cameras:

Test camera0:

sudo raspivid -t 0 -cs 0

Test camera1:

sudo raspivid -t 0 -cs 1

New Version (Bullseye)

If you are using the latest Raspberry Pi OS (Bullseye):

libcamera-hello -t 0
or
libcamera-hello

#The new system uses dual cameras
#Remove or comment out the line camera_auto_detect=1 in config.txt
#camera_auto_detect=1

#Add the following lines:
dtoverlay=imx219,cam1
dtoverlay=imx219,cam0


#Add the corresponding line according to the camera you use, where imx219 is the camera sensor model, and there are other sensors
dtoverlay=ov5647,cam0
dtoverlay=imx219,cam0
dtoverlay=ov9281,cam0
dtoverlay=imx477,cam0

#then restart
reboot

#Other part of the commands:
#Check if the camera is detected
libcamera-hello --list-cameras

#Open the corresponding camera
libcamera-hello --camera 1
libcamera-hello --camera 0

#Taking Pictures
libcamera-jpeg -o test.jpg
#You can add --camera to specify the camera

More instructions click me

  • HDMI1 is disabled if you use DSI interfaces for displaying, even if you just compile the corresponding files without connecting to the DSI screen, please note it
  • Any connection of two HDMI ports can output images, not limited to which HDMI port, if two HDMI screens are connected, only HDMI0 has image output
  • If you want to enable both HDMI, please delete the dt-blob.bin file with the following command:
sudo rm -rf /boot/dt-blob.bin
  • Then reboot

Reference Raspberry Pi Manual

Test Camera

  • Connect the camera to CSI interfaces
  • Connect power to the CM4 board
  • After booting, run command raspi-config and choose Interface Options -> Camera -> Yes -> Finish -> Yes.
  • Reboot CM4 and test the camera with the commands below
  • If you use Buster image
sudo raspivid -t 0 -cs 0
sudo raspivid -t 0 -cs 1
  • If you use Bullseye image
sudo libcamera-vid -t 0 -cs 0
sudo libcamera-vid -t 0 -cs 1