Error when trying to capture images with B0272

I have the B0272 Motorized Focus camera with the 12MP IMX477 imager connected to a Raspberry Pi 4B and I can’t get it to work.

I started with the latest Raspbian 64 bit image and added this to /boot/config.txt

[all]
dtparam=i2c_vc=on

I tried running the example code here, but that seems to require an older version of python-libcamera that is not compatible with the Raspberry Pi 4.

I then tried libcamera-hello and got the following output:

$ libcamera-hello
Preview window unavailable
[1:40:53.804743804] [2802]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[1:40:53.844235385] [2803]  WARN CameraSensorProperties camera_sensor_properties.cpp:163 No static properties available for 'imx477'
[1:40:53.844331532] [2803]  WARN CameraSensorProperties camera_sensor_properties.cpp:165 Please consider updating the camera sensor properties database
[1:40:53.844393846] [2803] ERROR CameraSensor camera_sensor.cpp:591 'imx477 10-001a': Camera sensor does not support test pattern modes.
[1:40:53.869082316] [2803]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media0 and ISP device /dev/media1
[1:40:53.869802884] [2802]  INFO Camera camera.cpp:1029 configuring streams: (0) 2028x1520-YUV420
[1:40:53.870131584] [2803]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-pBCC
[1:40:54.424903791] [2803] ERROR V4L2 v4l2_videodevice.cpp:1852 /dev/video14[15:cap]: Failed to start streaming: No such file or directory
ERROR: *** failed to start camera ***

And this error in dmesg:

[ 6054.484038] bcm2835-isp bcm2835-isp: bcm2835_isp_node_start_streaming: Failed enabling port, ret -2
[ 6054.484115] ------------[ cut here ]------------
[ 6054.484118] WARNING: CPU: 3 PID: 2803 at drivers/media/common/videobuf2/videobuf2-core.c:1552 vb2_start_streaming+0x10c/0x160 [videobuf2_common]
[ 6054.484142] Modules linked in: cmac algif_hash aes_arm64 algif_skcipher af_alg bnep hci_uart btbcm bluetooth ecdh_generic ecc 8021q garp stp llc imx477 snd_soc_hdmi_codec brcmfmac brcmutil cfg80211 rfkill vc4 cec v3d drm_kms_helper i2c_mux_pinctrl gpu_sched i2c_mux bcm2835_unicam snd_soc_core raspberrypi_hwmon bcm2835_v4l2(C) bcm2835_codec(C) bcm2835_isp(C) snd_compress v4l2_dv_timings v4l2_fwnode v4l2_mem2mem bcm2835_mmal_vchiq(C) videobuf2_vmalloc videobuf2_dma_contig v4l2_async i2c_brcmstb snd_bcm2835(C) snd_pcm_dmaengine videobuf2_memops videobuf2_v4l2 videobuf2_common snd_pcm i2c_bcm2835 videodev snd_timer mc vc_sm_cma(C) snd syscopyarea rpivid_mem sysfillrect sysimgblt fb_sys_fops uio_pdrv_genirq nvmem_rmem uio drm drm_panel_orientation_quirks fuse backlight ip_tables x_tables ipv6
[ 6054.484260] CPU: 3 PID: 2803 Comm: libcamera-hello Tainted: G        WC        5.15.32-v8+ #1538
[ 6054.484265] Hardware name: Raspberry Pi 4 Model B Rev 1.4 (DT)
[ 6054.484269] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 6054.484274] pc : vb2_start_streaming+0x10c/0x160 [videobuf2_common]
[ 6054.484285] lr : vb2_start_streaming+0x74/0x160 [videobuf2_common]
[ 6054.484294] sp : ffffffc00a77bb40
[ 6054.484296] x29: ffffffc00a77bb40 x28: 0000000000000000 x27: ffffffc00a77bd28
[ 6054.484305] x26: 0000000000000000 x25: ffffff8040966700 x24: ffffff80433bd328
[ 6054.484312] x23: 0000000000000001 x22: ffffffc008e8a9c8 x21: ffffff80433bd520
[ 6054.484319] x20: ffffff80433bd348 x19: 00000000fffffffe x18: 0000000000000001
[ 6054.484326] x17: 656c696146203a67 x16: 6e696d6165727473 x15: 5f74726174735f65
[ 6054.484333] x14: 646f6e5f7073695f x13: 322d20746572202c x12: ffffffc0093a6670
[ 6054.484339] x11: 0000000000000003 x10: ffffffc00938e630 x9 : ffffffc0080ec768
[ 6054.484346] x8 : 0000000000017fe8 x7 : c0000000ffffefff x6 : ffffff80fb7ce908
[ 6054.484353] x5 : ffffffc0f278e000 x4 : 0000000000000002 x3 : 0000000000000001
[ 6054.484360] x2 : 487d368a04fd4600 x1 : 0000000000000000 x0 : 0000000000000001
[ 6054.484367] Call trace:
[ 6054.484369]  vb2_start_streaming+0x10c/0x160 [videobuf2_common]
[ 6054.484380]  vb2_core_streamon+0x98/0x198 [videobuf2_common]
[ 6054.484390]  vb2_streamon+0x24/0x78 [videobuf2_v4l2]
[ 6054.484399]  vb2_ioctl_streamon+0x58/0x68 [videobuf2_v4l2]
[ 6054.484406]  v4l_streamon+0x2c/0x38 [videodev]
[ 6054.484442]  __video_do_ioctl+0x188/0x410 [videodev]
[ 6054.484467]  video_usercopy+0x310/0x7d0 [videodev]
[ 6054.484491]  video_ioctl2+0x20/0x38 [videodev]
[ 6054.484515]  v4l2_ioctl+0x48/0x68 [videodev]
[ 6054.484539]  __arm64_sys_ioctl+0xb0/0xf0
[ 6054.484547]  invoke_syscall+0x4c/0x110
[ 6054.484554]  el0_svc_common.constprop.3+0xfc/0x120
[ 6054.484559]  do_el0_svc+0x2c/0x90
[ 6054.484563]  el0_svc+0x24/0x60
[ 6054.484569]  el0t_64_sync_handler+0x90/0xb8
[ 6054.484573]  el0t_64_sync+0x1a0/0x1a4
[ 6054.484578] ---[ end trace f02470b761aef428 ]---

What can I do to debug this?

Hi @contradict

Try this:

That gets image capture working and eliminates the errors in dmesg! Is there an updated version of the python sample code that shows how to use the focus control on a Pi4?

OK! I think I got everything working. On a raspberry Pi 4 running the most recent 64bit Raspberry Pi OS Lite.

 $ cat /etc/debian_version
11.3
 $ uname -a
Linux toolcam 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux

Add these lines in /boot/config.txt

dtparam=i2c_vc=on
dtoverlay=imx477

And change the line camera_auto_detect=1 to camera_auto_detect=0

Add the line i2c-dev to /etc/modules.

Build libcamera and libcamera-apps according to the instructions here.

Then, when libcamera-vid is running (or any other preview tool), there is an i2c device at address 0x0C on /dev/i2c-10 that accepts a focus position. For a focus position between 0x000 and 0x3ff, the focus can be set by running.

i2cset -y 10 0x0C 0x3f 0xf0

This command will error unless some tool has the camera open, the I2C device does not appear to be configured when the camera is not running.