Arducam B0393 IMX219 autofocus not working with libcamera --continue-autofocus on Bullseye

B0393 8MP IMX219 autofocus not working with libcamera --continue-autofocus

Hi all,

I’ve got 2x Arducam B0393 8MP IMX219 autofocus cameras and I can’t get autofocus to work at all through libcamera. The camera does produce an image and almost every libcamera command I try works — it’s specifically --continue-autofocus that does nothing for the focus.

I also have a 16MP IMX519 camera and that one autofocuses fine with --continue-autofocus. The 8MP B0393 just won’t.

Command I’m running:

libcamera-still -t 0 --viewfinder-width 1280 --viewfinder-height 720 --continue-autofocus --rotation 180 #–roi 0.25,0.25,0.5,0.5

So far I’ve:

  • Followed everything in the camera Quick Start guide
  • Done updates and upgrades
  • Tried every recommendation I could find on the Arducam forum
  • Built a brand new Bullseye SD card from scratch and installed all the recommended items for the 8MP autofocus camera
  • Reinstalled all the required items

What am I missing for autofocus to work on the B0393? Are there bad or missing drivers for the --continue-autofocus command on IMX219? I’ve seen other people report the same thing on the Arducam and Raspberry Pi forums but no solutions. Thanks.

Hi, thanks for the detailed writeup. A couple of things to narrow down before I point you anywhere:

  • Are you testing the B0393 on the same Bullseye install where the IMX519 drivers are present, or on a clean one?
  • What does libcamera-hello --version and dpkg -l | grep libcamera show?

The reason I ask is that the IMX519 and IMX219 use completely different drivers and tunings, and mixing the two on one card can cause exactly this “image works but AF doesn’t” behavior. If you can confirm whether the IMX219 test was on a fresh card with no IMX519 bits on it, that helps a lot.

To answer that: the 8MP B0393 test was done on a fresh Bullseye SD card built from scratch, and there are no IMX519 drivers on that card at all. I keep the two separate because I know they use different drivers and can’t be interchanged.

Setup on the test card:

  • 2x Arducam B0393 8MP IMX219 autofocus cameras
  • New SD card, Bullseye installed from scratch
  • All the recommended items for the 8MP autofocus camera installed
  • No IMX519 drivers present

On the same card, a plain libcamera command gives me a picture just fine. It’s only the autofocus that’s dead.

Thanks, that confirms it’s not a driver conflict.

Here’s where things actually stand: the autofocus path that libcamera uses with the imx219 sensor is still under development on Arducam’s side — it isn’t implemented/complete yet. That’s why --continue-autofocus works on the IMX519 but does nothing on the IMX219 B0393. So it’s not something you’re doing wrong or a driver you forgot to install.

In the meantime you can drive the focus manually with the Python script in Arducam’s RaspberryPi repo:

That gives you motorized focus control while libcamera autofocus support is being finished. If you try it and hit errors, post them here and we’ll take a look.

Ok, I tried everything from that GitHub link and it did not work.

All of my 8MP IMX219 evaluation cameras will display an image with a simple libcamera command, but none of the python script examples work. No image comes up, I just get a quick black box for less than a second, and then this traceback:

pi@raspberrypi:~ $ cd RaspberryPi/Motorized_Focus_Camera/python/
pi@raspberrypi:~/RaspberryPi/Motorized_Focus_Camera/python $ python FocuserExample.py -i 10
Traceback (most recent call last):
  File "/home/pi/RaspberryPi/Motorized_Focus_Camera/python/FocuserExample.py", line 27, in <module>
    from RpiCamera import Camera
  File "/home/pi/RaspberryPi/Motorized_Focus_Camera/python/RpiCamera.py", line 10, in <module>
    from picamera2 import Picamera2, Preview
  File "/home/pi/.local/lib/python3.9/site-packages/picamera2/__init__.py", line 1, in <module>
    from .picamera2 import Picamera2, Preview
  File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 35, in <module>
    class Picamera2:
  File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 262, in Picamera2
    def preview_configuration(self, main={}, lores=None, raw=None, transform=libcamera.Transform(), colour_space=libcamera.ColorSpace.Jpeg(), buffer_count=4, controls={}, display="main", encode="main"):
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. libcamera.Transform(value: int)
Invoked with:
pi@raspberrypi:~/RaspberryPi/Motorized_Focus_Camera/python $

Environment: Raspberry Pi (user pi@raspberrypi), Python 3.9, picamera2 at /home/pi/.local/lib/python3.9/site-packages/picamera2/. I ran both python FocuserExample.py -i 10 and python3 FocuserExample.py and get the same result.

I need to test the autofocus somehow. Is there a timetable for getting libcamera autofocus and digital zoom working? Honestly that GitHub link looks either wrong or out of date. Could this be a missing component in the python script’s reaction?

Thanks for the traceback — that’s the useful part.

That error is a version mismatch, not a camera problem: picamera2 is calling libcamera.Transform() with no arguments, but the installed libcamera only accepts libcamera.Transform(value: int). So the picamera2 copy in /home/pi/.local/ was built against a different libcamera API than the one on your system. The example script is older than the libcamera you have installed.

A few things worth checking:

  • python3 -c "import picamera2; print(picamera2.__version__)" and libcamera-hello --version
  • whether picamera2 came in via pip into ~/.local (that copy often shadows the apt/system one)
  • try moving/renaming the ~/.local copy of picamera2 so the system package is used instead

Can you post the versions you get? That’ll tell us whether the motorized focus script can run at all on your current stack.

Here’s what I have:

  • Raspberry Pi, user pi@raspberrypi
  • Python 3.9
  • picamera2 living at /home/pi/.local/lib/python3.9/site-packages/picamera2/
  • 8MP IMX219 evaluation cameras

I still only reproduce the same TypeError from the local picamera2. I tried the repo items as-is and didn’t modify anything in the script itself, so I’m stuck on whether the script needs a fix or whether there’s a missing component in how it reacts to my setup. Either way I still need some way to test the autofocus.

To summarize where this leaves us:

  1. libcamera autofocus (–continue-autofocus) is not supported on the IMX219 / B0393 yet — it’s still under development, so no driver or install on your side will turn it on. That’s why the IMX519 behaves differently.
  2. The current workaround is the Python motorized-focus script, which controls focus directly instead of through libcamera autofocus.
  3. That script isn’t running for you because of the picamera2 vs libcamera version mismatch shown in the traceback (Transform() called with no args, while your libcamera only accepts Transform(int)). The ~/.local picamera2 copy is the likely culprit, since it was built against a different libcamera API.

So: the script workaround needs a matching picamera2/libcamera pairing to run at all, and libcamera-side autofocus plus digital zoom for the IMX219 are still pending completion. I can’t give you a firm date for that yet. If you post the picamera2 and libcamera versions, we can at least confirm whether the script can be made to run on your current image while you wait.