# how to debug camera issues on a Raspberry Pi Zero W
sudo apt update
sudo apt install -y raspi-config
sudo apt full-upgrade
# enable i2c manually;
sudo nano /boot/firmware/config.txt
# enable or add this line, it should be commented in the first 10 lines of the file:
dtparam=i2c_arm=on
# reboot
sudo reboot
# verify if the camera is on the i2c bus
sudo apt install i2c-tools -y
sudo i2cdetect -y 1
# list the i2c device nodes:
ls /dev/i2c*
# if no devices are listed, load it manually:
sudo modprobe i2c-dev
# list
lsmod | grep i2c
# if you see devices after loading manually, load automatically on boot:
echo "i2c-dev" | sudo tee -a /etc/modules
cat /etc/modules
sudo reboot
sudo i2cdetect -y 1
# Test the camera:
libcamera-hello
# test grabbing a frame
libcamera-still -o test.jpg
# if you get this:
libcamera-still -o test.jpg
Could not open any dmaHeap device
[0:26:54.411895865] [2020] INFO Camera camera_manager.cpp:325 libcamera v0.3.2+27-7330f29b
[0:26:54.571953915] [2023] ERROR DmaBufAllocator dma_buf_allocator.cpp:116 Could not open any dma-buf provider
[0:26:54.955948630] [2023] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:26:54.979878236] [2023] ERROR RPI vc4.cpp:216 Failed to register camera ov5647 10-0036: -12
Preview window unavailable
ERROR: *** no cameras available ***
# then try sudo
sudo libcamera-still -o test.jpg
# the output using sudo should look something like:
[0:27:24.048860725] [2028] INFO Camera camera_manager.cpp:325 libcamera v0.3.2+27-7330f29b
[0:27:24.592784487] [2033] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:27:24.624990302] [2033] INFO RPI vc4.cpp:447 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
[0:27:24.629344412] [2033] INFO RPI pipeline_base.cpp:1126 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Mode selection for 1296:972:12:P
SGBRG10_CSI2P,640x480/0 - Score: 3296
SGBRG10_CSI2P,1296x972/0 - Score: 1000
SGBRG10_CSI2P,1920x1080/0 - Score: 1349.67
SGBRG10_CSI2P,2592x1944/0 - Score: 1567
Stream configuration adjusted
[0:27:24.672293499] [2028] INFO Camera camera.cpp:1197 configuring streams: (0) 1296x972-YUV420 (1) 1296x972-SGBRG10_CSI2P
[0:27:24.678434654] [2033] INFO RPI vc4.cpp:622 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAA
#0 (0.00 fps) exp 33222.00 ag 8.00 dg 1.00
#1 (30.02 fps) exp 29995.00 ag 2.50 dg 2.55
#2 (30.02 fps) exp 29995.00 ag 2.50 dg 2.55
#3 (30.01 fps) exp 29995.00 ag 2.50 dg 2.55
#4 (15.01 fps) exp 29995.00 ag 2.50 dg 2.55
...
#110 (30.02 fps) exp 33222.00 ag 5.50 dg 1.01
Mode selection for 2592:1944:12:P
SGBRG10_CSI2P,640x480/0 - Score: 7832
SGBRG10_CSI2P,1296x972/0 - Score: 5536
SGBRG10_CSI2P,1920x1080/0 - Score: 4238.67
SGBRG10_CSI2P,2592x1944/0 - Score: 1000
Stream configuration adjusted
[0:27:29.934713646] [2028] INFO Camera camera.cpp:1197 configuring streams: (0) 2592x1944-YUV420 (1) 2592x1944-SGBRG10_CSI2P
[0:27:29.964616403] [2033] INFO RPI vc4.cpp:622 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 2592x1944-SGBRG10_1X10 - Selected unicam format: 2592x1944-pGAA
Still capture image received
# if it works with sudo, then add your user to the video group.
# as a user (not as root), run:
sudo usermod -aG video $USER
newgrp video
# then run again but WITHOUT sudo:
libcamera-still -o test.jpg
# check that you have camera access as non-root, that you don't get permission denied:
cat /dev/video0 > /dev/null
# CONTROL C to cancel.
# if it said permission denied:
sudo chown root:video /dev/video*
sudo chmod 660 /dev/video*
libcamera-hello
# if it still doesn't work:
# create a new udev rule file:
sudo nano /etc/udev/rules.d/99-camera.rules
# add this line to the file:
KERNEL=="video[0-9]*", GROUP="video", MODE="0660"
# reload
sudo udevadm control --reload-rules
sudo udevadm trigger
# it's likely this:
sudo chmod 660 /dev/dma_heap*
sudo chown root:video /dev/dma_heap*
sudo nano /etc/udev/rules.d/99-dma_heap.rules
# with contents:
KERNEL=="dma_heap*", GROUP="video", MODE="0660"
#reload
sudo udevadm control --reload-rules
sudo udevadm trigger
libcamera-hello
# if there are still issues:
ls -l /dev/dma_heap*
ls: cannot access '/dev/dma_heap/system': Permission denied
ls: cannot access '/dev/dma_heap/linux,cma': Permission denied
total 0
c????????? ? ? ? ? ? linux,cma
c????????? ? ? ? ? ? system
# it could be app armor
sudo aa-status
sudo systemctl stop apparmor
libcamera-hello
# it still doesn't work
ls -l /dev/dma_heap/*
sudo chmod 660 /dev/dma_heap/*
sudo chown root:video /dev/dma_heap/*
sudo reboot
# list again:
ls -l /dev/dma_heap*
total 0
crw------- 1 root root 253, 1 Nov 18 23:45 linux,cma
crw------- 1 root root 253, 0 Nov 18 23:45 system
# it's root:root, and we are in group video, so we need:
sudo chown root:video /dev/dma_heap/*
# if it still doesn't run as user, run the 1st command as root, ex:
libcamera-vid -t 0 --width 320 --height 240 --framerate 30 -o - | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://0.0.0.0:8554/' :demux=h264