Camera not working on Zero2 + Balena-Cam

Output from the logs of my running Zero2 device with balena-cam:

04.03.22 20:54:09 (+0100)  balena-cam    from cryptography.hazmat.backends import default_backend
04.03.22 20:54:10 (+0100)  balena-cam  Video device is not ready
04.03.22 20:54:10 (+0100)  balena-cam  Trying to load bcm2835-v4l2 driver...
04.03.22 20:54:13 (+0100) Service exited 'balena-cam sha256:75027ec2c1867aa4c2f66e41ee2a4a2c5ad058ff6418258cac0a0b7977e35f10'

Same Camera was working with the old Raspberry Pi Zero.

dmesg:

root@602b67b:~# dmesg | grep bcm2835
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=Composite-1:720x480@60i smsc95xx.macaddr=B8:27:EB:6A:AA:0F vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 rootwait  vt.global_cursor_default=0 console=null cgroup_enable=memory root=UUID=4933a0f6-0826-4423-996e-85631a5e9d12 rootwait
[    0.143163] bcm2835-mbox 3f00b880.mailbox: mailbox enabled
[    0.196754] bcm2835-dma 3f007000.dma: DMA legacy API manager, dmachans=0x1
[    2.172906] bcm2835-rng 3f104000.rng: hwrng registered
[    2.175391] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[    2.717644] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[    2.722417] mmc-bcm2835 3f300000.mmcnr: could not get clk, deferring probe
[    2.724105] sdhost-bcm2835 3f202000.mmc: could not get clk, deferring probe
[    2.760945] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[    2.763668] mmc-bcm2835 3f300000.mmcnr: mmc_debug:0 mmc_debug2:0
[    2.763687] mmc-bcm2835 3f300000.mmcnr: DMA channel allocated
[    2.840123] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[   17.989290] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[   17.996597] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[   17.999872] bcm2835_audio bcm2835_audio: there is not valid maps for state default
[   18.107274] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[   18.110853] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[   18.200048] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[   18.208927] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[   18.211168] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[   18.263545] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[   18.263772] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[   18.274586] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[  192.372559]  bcm2835_dma_create_cb_chain+0x70/0x350
[  192.372567]  bcm2835_dma_prep_slave_sg+0x124/0x350
[  192.372578]  bcm2835_sdhost_request+0x3d8/0x670
[ 1078.433215] WARNING: CPU: 3 PID: 1783 at drivers/mmc/host/bcm2835-mmc.c:495 bcm2835_mmc_transfer_dma+0x210/0x238
[ 1078.433221] Modules linked in: ip6t_REJECT nf_reject_ipv6 ip6table_filter xt_state ipt_REJECT nf_reject_ipv4 ip6_tables xt_MASQUERADE nf_conntrack_netlink nfnetlink br_netfilter cmac algif_hash aes_arm64 algif_skcipher af_alg bnep hci_uart btbcm bluetooth ecdh_generic ecc xt_owner i2c_dev brcmfmac brcmutil sha256_generic bcm2835_isp(C) bcm2835_codec(C) bcm2835_v4l2(C) cfg80211 v4l2_mem2mem bcm2835_mmal_vchiq(C) videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops rfkill videobuf2_v4l2 videobuf2_common raspberrypi_hwmon videodev sdhci_iproc mc spi_bcm2835 snd_bcm2835(C) vc_sm_cma(C) uio_pdrv_genirq uio sch_fq_codel
[ 1078.433529] pc : bcm2835_mmc_transfer_dma+0x210/0x238
[ 1078.433537] lr : bcm2835_mmc_request+0xa4/0xc0
[ 1078.433746]  bcm2835_mmc_transfer_dma+0x210/0x238
[ 1078.433754]  bcm2835_mmc_request+0xa4/0xc0

Fleet custom configurations: (working values with Zero 1)

BALENA_HOST_CONFIG_gpu_mem_1024 448
BALENA_HOST_CONFIG_gpu_mem_256 192
BALENA_HOST_CONFIG_gpu_mem_512 256

Any idea why balena-cam is not running on my Raspberry Pi Zero2?

Hi @leon22,

Are you building this as a multicontainer app (using docker-compose.yml) or is this a single Dockerfile build?

If it is docker-compose, do you mind sharing your docker-compose.yml file?

cat docker-compose.yml
version: '2'
services:
        balena-cam:
                build: ./balena-cam
                privileged: true
                restart: always
                network_mode: "host"
                labels:
                        io.balena.features.kernel-modules: '1'

Hello,

According to the code that tries to load the camera: balena-cam/server.py at master · balenalabs/balena-cam · GitHub
Can you check on container level and on hostOS level if there are any /dev/videoX devices loaded and share the results?
Can you check if you can run the modprobe bcm2835-v4l2 on the container and on the hostOS level and share the results?

In addition, I’ve found this from RaspberryPi forums: Pi Zero 2 W camera troubles - Raspberry Pi Forums
In the meantime, I’ll check if we have faced this issue already and found a solution to it.

Best Regards
Harald

1 Like

Hey there
Can you confirm if you have set up the required device configurations as described here: GitHub - balenalabs/balena-cam: Network Camera with Raspberry Pi and WebRTC. Tutorial:

Thanks

Here is the information you asked for:

root@53e08c8:~# ls /dev/video*
ls: cannot access ‘/dev/video*’: No such file or directory
root@53e08c8:~# modprobe bcm2835-v4l2
root@53e08c8:~# dmesg | grep bcm2835
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=Composite-1:720x480@60i smsc95xx.macaddr=B8:27:EB:6A:AA:0F vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 rootwait console=tty1 console=ttyS0,115200 cgroup_enable=memory root=UUID=c0b74979-357f-4102-9485-8270681d7897 rootwait
[ 0.144647] bcm2835-mbox 3f00b880.mailbox: mailbox enabled
[ 0.198229] bcm2835-dma 3f007000.dma: DMA legacy API manager, dmachans=0x1
[ 2.236528] bcm2835-aux-uart 3f215040.serial: there is not valid maps for state default
[ 2.241295] bcm2835-rng 3f104000.rng: hwrng registered
[ 2.250144] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[ 2.885999] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[ 2.895413] mmc-bcm2835 3f300000.mmcnr: could not get clk, deferring probe
[ 2.898605] sdhost-bcm2835 3f202000.mmc: could not get clk, deferring probe
[ 2.965648] bcm2835-aux-uart 3f215040.serial: there is not valid maps for state default
[ 4.228080] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[ 4.239787] mmc-bcm2835 3f300000.mmcnr: mmc_debug:0 mmc_debug2:0
[ 4.247447] mmc-bcm2835 3f300000.mmcnr: DMA channel allocated
[ 4.354870] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[ 20.164140] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 20.168243] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.214976] bcm2835_audio bcm2835_audio: there is not valid maps for state default
[ 20.276136] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.276151] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.281909] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.294431] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.297696] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[ 20.298018] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.310100] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.314674] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[ 20.315926] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
root@53e08c8:~# ls /dev/video*
ls: cannot access ‘/dev/video*’: No such file or directory
root@53e08c8:~# modprobe bcm2835-v4l2
root@53e08c8:~# dmesg | grep bcm2835-v4l2
root@53e08c8:~# dmesg | grep bcm2835
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=Composite-1:720x480@60i smsc95xx.macaddr=B8:27:EB:6A:AA:0F vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 rootwait console=tty1 console=ttyS0,115200 cgroup_enable=memory root=UUID=c0b74979-357f-4102-9485-8270681d7897 rootwait
[ 0.144647] bcm2835-mbox 3f00b880.mailbox: mailbox enabled
[ 0.198229] bcm2835-dma 3f007000.dma: DMA legacy API manager, dmachans=0x1
[ 2.236528] bcm2835-aux-uart 3f215040.serial: there is not valid maps for state default
[ 2.241295] bcm2835-rng 3f104000.rng: hwrng registered
[ 2.250144] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[ 2.885999] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[ 2.895413] mmc-bcm2835 3f300000.mmcnr: could not get clk, deferring probe
[ 2.898605] sdhost-bcm2835 3f202000.mmc: could not get clk, deferring probe
[ 2.965648] bcm2835-aux-uart 3f215040.serial: there is not valid maps for state default
[ 4.228080] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[ 4.239787] mmc-bcm2835 3f300000.mmcnr: mmc_debug:0 mmc_debug2:0
[ 4.247447] mmc-bcm2835 3f300000.mmcnr: DMA channel allocated
[ 4.354870] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[ 20.164140] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 20.168243] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.214976] bcm2835_audio bcm2835_audio: there is not valid maps for state default
[ 20.276136] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.276151] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.281909] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.294431] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.297696] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[ 20.298018] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.310100] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[ 20.314674] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
[ 20.315926] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1)
root@53e08c8:~# lsmod | grep bcm2835
bcm2835_isp 32768 0
bcm2835_codec 49152 0
bcm2835_v4l2 45056 0
v4l2_mem2mem 40960 1 bcm2835_codec
bcm2835_mmal_vchiq 40960 3 bcm2835_codec,bcm2835_v4l2,bcm2835_isp
videobuf2_dma_contig 24576 2 bcm2835_codec,bcm2835_isp
videobuf2_vmalloc 20480 1 bcm2835_v4l2
videobuf2_v4l2 32768 4 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem,bcm2835_isp
videobuf2_common 61440 5 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,v4l2_mem2mem,bcm2835_isp
videodev 315392 6 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
snd_bcm2835 28672 0
spi_bcm2835 24576 0
mc 61440 6 videodev,bcm2835_codec,videobuf2_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
vc_sm_cma 36864 2 bcm2835_mmal_vchiq,bcm2835_isp

I’m not able to connect to the balena-cam service as it is in restarting mode all the time. One side comment: after switching off the power and on again the device is not able to reconnect to the belena servers.

I also tried with the newest balenaOS (v2.94.4) with no success.

The configuration parameters from GitHub - balena-labs-projects/balena-cam: Network Camera with Raspberry Pi and WebRTC. Tutorial: are also set.

Any news?

I have not enough space to use a e.g. Raspberry Pi 4, so I depend on the RPZero2.

Hello, one of our community members recently provided an update to balenaCam that was just merged and it should no longer result in a restart loop. I have it successfully running on a Pi Zero 2W, however, I did have some issues with the memory settings. On a Zero 2W only, I would just set the GPU memory at 64 MB instead of the BALENA_HOST_CONFIG_gpu_mem_ settings as described. You’ll still need to set BALENA_HOST_CONFIG_start_x to 1.

1 Like

Thx, but the download process is not successful:

Downloading image ‘registry2.balena-cloud.com/v2/…’ stuck at 58% for 40 minutes.

31.03.22 21:30:05 (+0200) Supervisor starting
31.03.22 21:30:31 (+0200) Supervisor starting
31.03.22 21:30:37 (+0200) Applying configuration change {“SUPERVISOR_POLL_INTERVAL”:“900000”,“SUPERVISOR_DELTA”:“1”,“SUPERVISOR_DELTA_REQUEST_TIMEOUT”:“59000”,“SUPERVISOR_DELTA_VERSION”:“3”}
31.03.22 21:30:37 (+0200) Applying boot config: {“start_x”:“1”,“gpu_mem”:“64”,“avoid_warnings”:“1”,“disable_overscan”:“1”,“disable_splash”:“1”,“dtoverlay”:[“vc4-fkms-v3d”],“dtparam”:[“audio=on”,“i2c_arm=on”,“spi=on”,“audio=on”]}
31.03.22 21:30:37 (+0200) Applied boot config: {“start_x”:“1”,“gpu_mem”:“64”,“avoid_warnings”:“1”,“disable_overscan”:“1”,“disable_splash”:“1”,“dtoverlay”:[“vc4-fkms-v3d”],“dtparam”:[“audio=on”,“i2c_arm=on”,“spi=on”,“audio=on”]}
31.03.22 21:30:37 (+0200) Applying boot config: {}
31.03.22 21:30:37 (+0200) Applied configuration change {“SUPERVISOR_POLL_INTERVAL”:“900000”,“SUPERVISOR_DELTA”:“1”,“SUPERVISOR_DELTA_REQUEST_TIMEOUT”:“59000”,“SUPERVISOR_DELTA_VERSION”:“3”}
31.03.22 21:30:38 (+0200) Applied boot config: {}
31.03.22 21:30:54 (+0200) Supervisor starting
31.03.22 21:30:55 (+0200) Creating network ‘default’
31.03.22 21:30:56 (+0200) Downloading image ‘registry2.balena-cloud.com/v2/dd4736e127070395db180de1ebdd227d@sha256:c4cebfda0143d0db8aff1c7bd666589c3ad60b8d7684df2f2ee413a4dc1dedb9
31.03.22 21:31:16 (+0200) Supervisor starting
31.03.22 21:31:17 (+0200) Downloading image ‘registry2.balena-cloud.com/v2/dd4736e127070395db180de1ebdd227d@sha256:c4cebfda0143d0db8aff1c7bd666589c3ad60b8d7684df2f2ee413a4dc1dedb9

Any more ideas?

Thx

PS: Very hard to install balena-cam on RPZero2. Had not expected so many problems.

I had some difficulty with the download as well but I’m not yet sure what the cause is. Eventually mine went through. I also plugged in a USB OTG Ethernet adapter just for the downloading and that worked immediately, which leads me to suspect a WiFi issue of some sort.

Thx!

Finally it is working. (I also used an USB-Ethernet adapter to successfully download the image)
That was an odysee :wink: