Arducam IMX519 autofocus camera out of focus, no focus algorithm on Pi Zero W

Hi everyone, I’m having trouble with an Arducam IMX519 autofocus camera (X003A6TSMX) on a Raspberry Pi Zero W. The image and video are always out of focus no matter what I try. I followed the paper manual and the docs at 16MP IMX519 - Arducam Wiki. I’m running libcamera v0.3.0+65-6ddd79b5. Whenever I test the camera, the Pi prints a warning about ‘no focus algorithm’. I’d really like to get autofocus working on what is supposed to be an autofocus camera. Anyone run into this?

Thanks for the details. That ‘no focus algorithm’ warning is the key clue. Can you run a basic still capture and paste the full terminal output? Try:

libcamera-still -t 5000 -n -o test.jpg

The log will show exactly what’s failing.

Here is the full output from that capture:

user@berrypi:~ $ libcamera-still -t 5000 -n -o test.jpg
[1:21:58.674074088] [2219]  INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5
[1:21:59.041290740] [2222]  WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[1:21:59.056586600] [2222]  INFO RPI vc4.cpp:446 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[1:21:59.057919588] [2222]  INFO RPI pipeline_base.cpp:1104 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Mode selection for 2328:1748:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 5319.24
    SRGGB10_CSI2P,1920x1080/0 - Score: 3319.24
    SRGGB10_CSI2P,2328x1748/0 - Score: 1000
    SRGGB10_CSI2P,3840x2160/0 - Score: 1648.24
    SRGGB10_CSI2P,4656x3496/0 - Score: 2019
Stream configuration adjusted
[1:21:59.076898415] [2219]  INFO Camera camera.cpp:1183 configuring streams: (0) 2328x1748-YUV420 (1) 2328x1748-SRGGB10_CSI2P
[1:21:59.080240384] [2222]  INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA
[1:21:59.124986976] [2226]  WARN IPARPI ipa_base.cpp:732 Could not set AF_MODE - no AF algorithm
[1:21:59.126374964] [2226]  WARN IPARPI ipa_base.cpp:1114 Could not set AF_SPEED - no focus algorithm
[1:21:59.127804951] [2226]  WARN IPARPI ipa_base.cpp:1096 Could not set AF_RANGE - no focus algorithm
Mode selection for 4656:3496:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 13471.2
    SRGGB10_CSI2P,1920x1080/0 - Score: 11471.2
    SRGGB10_CSI2P,2328x1748/0 - Score: 9152
    SRGGB10_CSI2P,3840x2160/0 - Score: 5471.24
    SRGGB10_CSI2P,4656x3496/0 - Score: 1000
Stream configuration adjusted
[1:22:04.417934799] [2219]  INFO Camera camera.cpp:1183 configuring streams: (0) 4656x3496-YUV420 (1) 4656x3496-SRGGB10_CSI2P
[1:22:04.461365404] [2222]  INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[1:22:04.507466985] [2229]  WARN IPARPI ipa_base.cpp:732 Could not set AF_MODE - no AF algorithm
[1:22:04.509104970] [2229]  WARN IPARPI ipa_base.cpp:1114 Could not set AF_SPEED - no focus algorithm
[1:22:04.512117943] [2229]  WARN IPARPI ipa_base.cpp:1096 Could not set AF_RANGE - no focus algorithm
Still capture image received

Thanks. That log shows autofocus is not even being enabled:

[1:21:59.124986976] [2226]  WARN IPARPI ipa_base.cpp:732 Could not set AF_MODE - no AF algorithm
[1:21:59.126374964] [2226]  WARN IPARPI ipa_base.cpp:1114 Could not set AF_SPEED - no focus algorithm
[1:21:59.127804951] [2226]  WARN IPARPI ipa_base.cpp:1096 Could not set AF_RANGE - no focus algorithm

In other words, your current libcamera setup has no focus algorithm, so autofocus can’t run. Before digging further into the software, can you post a clear photo of the front and back of the camera module? I want to verify the module and hardware look correct.

While I was getting those photos, I went back through some older threads. I already tried these and none of them helped:

A couple of them mention similar ‘no AF algorithm’ errors, but I couldn’t figure out what actually applies to the Pi Zero W.

The Arducam libcamera packages have been updated since some of those threads. Please follow the update steps in this post and run the install sequence:

Paste the install output back here when you’re done.

Okay, I went through the update steps. Here’s my current environment:

Hardware Revision: 9000c1
Kernel Version: 6.6.47+
OS Codename: bookworm
ARCH: armv6l

Commands I ran, in order:

  1. ./install_pivariety_pkgs.sh -p -l
  2. ./install_pivariety_pkgs.sh -p libcamera_dev
  3. ./install_pivariety_pkgs.sh -p libcamera_apps
  4. sudo apt update && sudo apt upgrade
  5. apt-cache search libcamera
  6. apt-cache search pivariety
  7. wget https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/libcamera-v0.0.5/libcamera0.3_0.3.1+rpt20240909-1_armhf.deb
  8. sudo dpkg -i libcamera0.3_0.3.1+rpt20240909-1_armhf.deb
  9. libcamera-still -t 500 -v -o test.jpg

The install script printed this (note the ‘Unsupported package’ bit):

user@berrypi:~ $ ./install_pivariety_pkgs.sh -p -l
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps
=================================================
Hardware Revision: 9000c1
Kernel Version: 6.6.47+
OS Codename: bookworm
ARCH: armv6l
=================================================
kernel:6.6.47+
kernel version is:
Unsupported package.
Supported packages:
        ov64a40_kernel_driver
        imx519_kernel_driver_low_speed
        imx708_kernel_driver
        libcamera
        64mp_pi_hawk_eye_kernel_driver
        libcamera_bookworm
        libcamera_apps
        libcamera_apps_bookworm
        imx708_b0311_kernel_driver
        libcamera_dev
        imx519_kernel_driver
        kernel_driver
=================================================
Hardware Revision: 9000c1
Kernel Version: 6.6.47+
OS Codename: bookworm
ARCH: armv6l
=================================================
kernel:6.6.47+
kernel version is:
--2024-09-10 12:17:23--  https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/libcamera_bookworm_links.txt

Then the capture after the update:

user@berrypi:~ $ libcamera-still -t 500 -v -o test.jpg
[1:28:28.311686801] [28400]  INFO Camera camera_manager.cpp:316 libcamera v0.3.1+74-a65f44f4-dirty (2024-09-09T07:57:44BST)
[1:28:28.906245588] [28403]  INFO RPI vc4.cpp:455 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[1:28:28.906707584] [28403]  INFO RPI pipeline_base.cpp:1150 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Running without preview window
Opening camera...
Acquired camera /base/soc/i2c0mux/i2c@1/imx519@1a
Configuring viewfinder...
Viewfinder size chosen is 2328x1748
Mode selection for 2328:1748:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 5319.24
    SRGGB10_CSI2P,1920x1080/0 - Score: 3319.24
    SRGGB10_CSI2P,2328x1748/0 - Score: 1000
Stream configuration adjusted
[1:28:28.929882420] [28400]  INFO Camera camera.cpp:1191 configuring streams: (0) 2328x1748-YUV420 (1) 2328x1748-SRGGB10_CSI2P
[1:28:28.947626294] [28403]  INFO RPI vc4.cpp:630 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA

For reference, these are the old AF warnings from before the update (they no longer appear):

[1:21:59.124986976] [2226]  WARN IPARPI ipa_base.cpp:732 Could not set AF_MODE - no AF algorithm
[1:21:59.126374964] [2226]  WARN IPARPI ipa_base.cpp:1114 Could not set AF_SPEED - no focus algorithm
[1:21:59.127804951] [2226]  WARN IPARPI ipa_base.cpp:1096 Could not set AF_RANGE - no focus algorithm

The image is still out of focus though.

Thanks, that’s useful. Two things stand out:

  1. The install script flagged your combination as ‘Unsupported package’ (kernel 6.6.47+, bookworm, armv6l), so the update may not have been fully applied.
  2. On the plus side, the ‘no AF algorithm’ warnings are gone after the update.

Let’s test whether autofocus can be triggered explicitly:

libcamera-still -o test1.jpg --autofocus-on-capture

Run that and paste the output.

Just ran it. It captures without errors, but the picture is still blurred. Output:

user@berrypi:~ $ libcamera-still -o test1.jpg --autofocus-on-capture
[0:04:07.317880850] [1784]  INFO Camera camera_manager.cpp:316 libcamera v0.3.1+74-a65f44f4-dirty (2024-09-09T07:57:44BST)
[0:04:07.926410108] [1787]  INFO RPI vc4.cpp:455 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[0:04:07.930311097] [1787]  INFO RPI pipeline_base.cpp:1150 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Mode selection for 2328:1748:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 5319.24
    SRGGB10_CSI2P,1920x1080/0 - Score: 3319.24
    SRGGB10_CSI2P,2328x1748/0 - Score: 1000
    SRGGB10_CSI2P,3840x2160/0 - Score: 1648.24
    SRGGB10_CSI2P,4656x3496/0 - Score: 2019
Stream configuration adjusted
[0:04:07.959062015] [1784]  INFO Camera camera.cpp:1191 configuring streams: (0) 2328x1748-YUV420 (1) 2328x1748-SRGGB10_CSI2P
[0:04:07.970509983] [1787]  INFO RPI vc4.cpp:630 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA
#0 (0.00 fps) exp 23901.00 ag 2.00 dg 2.32
#1 (30.00 fps) exp 23901.00 ag 2.00 dg 2.32
#2 (30.00 fps) exp 29990.00 ag 3.57 dg 1.04
#3 (29.99 fps) exp 29990.00 ag 3.57 dg 1.04
...
#95 (10.00 fps) exp 32158.00 ag 4.00 dg 1.00
Mode selection for 4656:3496:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 13471.2
    SRGGB10_CSI2P,1920x1080/0 - Score: 11471.2
    SRGGB10_CSI2P,2328x1748/0 - Score: 9152
    SRGGB10_CSI2P,3840x2160/0 - Score: 5471.24
    SRGGB10_CSI2P,4656x3496/0 - Score: 1000
Stream configuration adjusted
[0:04:16.470617452] [1784]  INFO Camera camera.cpp:1191 configuring streams: (0) 4656x3496-YUV420 (1) 4656x3496-SRGGB10_CSI2P
[0:04:16.568488296] [1787]  INFO RPI vc4.cpp:630 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
Still capture image received

I trimmed the repetitive frame lines in the middle; they just kept running through exposure/fps values.

That capture ran cleanly with no AF errors, and the stream configuration looks normal, so the pipeline itself is working. The focus problem is still there though. Two pieces of info will help narrow it down:

  • How far is the object from the lens? If it’s very close, you may be below the module’s minimum focus distance.
  • Can you attach a couple of the out-of-focus JPEGs so we can see whether it’s hunting for focus or just stuck at a fixed point?

Good news — I gave up trying to patch the existing install and just formatted the SD card, reinstalled the OS, and reinstalled all the camera packages from scratch. Autofocus is now working perfectly. I’m not entirely sure which leftover package or kernel mismatch was the problem, but a clean install cleared it.

Great, that confirms it was a software/package state issue rather than the module itself. To summarize for anyone landing here: the original ‘no AF algorithm’ warnings were fixed by the updated Arducam libcamera packages, but autofocus still wouldn’t work until the OS was reinstalled cleanly. The likely culprit was a mismatched or leftover package state from the earlier partial update — the install script had flagged kernel 6.6.47+/bookworm/armv6l as ‘Unsupported package’. A fresh OS install with the updated libcamera packages got autofocus working. If it ever returns, I’d check that the kernel and libcamera package versions match before doing anything else.