RuntimeError: AfMode not advertised by libcamera in picamera2 on Raspberry Pi IMX519 16MP Autofocus

Hi everyone, I’m testing out a batch of Arducam IMX519 16MP Autofocus cameras and I’m stuck on an autofocus issue. My Python script throws:

RuntimeError: Control AfMode is not advertised by libcamera

This happens right at startup when I try to set the autofocus controls:

self.picam2.set_controls({"AfMode": controls.AfModeEnum.Auto, "AfTrigger": controls.AfTriggerEnum.Start})

Environment details:

  • libcamera v0.0.5+83-bde9b04f
  • Raspberry Pi vc4 pipeline
  • Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a
  • Lens: ak7375 10-000c
  • Script: /home/pi/BABU/NEW_UI/auto.py
  • picamera2 from /usr/lib/python3/dist-packages/picamera2/
  • Config file: /usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml

Log output:

[0:07:57.380360899] [1552] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:07:57.423093362] [1573] ERROR V4L2 v4l2_device.cpp:93 'ak7375 10-000c': Failed to open V4L2 device '/dev/v4l-subdev1': Invalid argument
[0:07:57.423199102] [1573] ERROR CameraSensor camera_sensor.cpp:527 'imx519 10-001a': Lens initialisation failed, lens disabled
[0:07:57.449205462] [1573] INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media1 and ISP device /dev/media3
[0:07:57.449313405] [1573] INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[0:07:57.467523237] [1552] INFO Camera camera.cpp:1033 configuring streams: (0) 3000x2456-XBGR8888 (1) 4656x3496-SRGGB10_CSI2P
[0:07:57.470597582] [1573] INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA

Then the full traceback:

Traceback (most recent call last):
  File "/home/pi/BABU/NEW_UI/auto.py", line 403, in <module>
    window = Auto()
  File "/home/pi/BABU/NEW_UI/auto.py", line 52, in __init__
    self.picam2.set_controls({"AfMode": controls.AfModeEnum.Auto, "AfTrigger": controls.AfTriggerEnum.Start})
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1093, in set_controls
    self.controls.set_controls(controls)
  File "/usr/lib/python3/dist-packages/picamera2/controls.py", line 58, in set_controls
    self.__setattr__(k, v)
  File "/usr/lib/python3/dist-packages/picamera2/controls.py", line 33, in __setattr__
    raise RuntimeError(f"Control {name} is not advertised by libcamera")
RuntimeError: Control AfMode is not advertised by libcamera

Any ideas what’s going wrong?

Looking at your logs, the important lines are these:

[0:07:57.423093362] [1573] ERROR V4L2 v4l2_device.cpp:93 'ak7375 10-000c': Failed to open V4L2 device '/dev/v4l-subdev1': Invalid argument
[0:07:57.423199102] [1573] ERROR CameraSensor camera_sensor.cpp:527 'imx519 10-001a': Lens initialisation failed, lens disabled

The autofocus lens actuator (ak7375) fails to open the V4L2 device /dev/v4l-subdev1 with ‘Invalid argument’. That causes the imx519 lens initialisation to fail, so the lens gets disabled. Because the lens is disabled, libcamera doesn’t advertise the AfMode control at all — which is exactly why picamera2 raises ‘Control AfMode is not advertised by libcamera’ when you try to set AfMode/AfTrigger.

So the AfMode issue is a symptom of the lens init failure, not something wrong with your set_controls call.

To dig into this further, could you generate an Arducam camera bug report? Please do the following:

  1. Reboot your device.
  2. Download the bug report tool:
wget -O arducam-camera-bug-report https://github.com/ketai-dhr/arducam-camera-bug-report/releases/download/tools/arducam-camera-bug-report
  1. Make it executable:
chmod +x ./arducam-camera-bug-report
  1. Run it:
./arducam-camera-bug-report

That will produce an arducam-bug-report.txt file in the current directory. Send that over and we’ll take a closer look.

Thanks for the explanation. I rebooted, ran the tool, and it generated arducam-bug-report.txt. I’ve sent the file over in a private message so you can review it. What should I try next?

Just following up — any update on this? I’m blocked on testing until the autofocus issue gets sorted.

Thanks for your patience, and thanks for sending the bug report. Based on what we’ve seen so far, the next step is to install the Arducam-provided libcamera build. The standard build isn’t fully handling the IMX519 autofocus actuator, which is why the lens gets disabled and the AfMode/AfTrigger controls aren’t advertised.

Please follow the getting-started section of the Arducam libcamera user guide:

https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Libcamera-User-Guide/#getting-started

After installing the Arducam-specific libcamera build, the IMX519 autofocus controls (AfMode/AfTrigger) should be properly advertised and usable. If you still see the ‘lens disabled’ error or ‘Control AfMode is not advertised by libcamera’ after that, post back and we’ll continue troubleshooting from there.