IMX519 camera on Raspberry Pi 4 stays out of focus with libcamera autofocus

Hi all, hoping someone can help. I’ve got an IMX519 camera hooked up to a Raspberry Pi 4 and I just can’t get it to focus. The image seems to stay out of focus no matter what I do.

The camera does work now (I get a picture), but I can’t get it to focus at all. When I run the focus script it goes through the motion of adjusting the focus, but nothing actually seems to change in the image.

For context, previously when I ran the capture command I was getting errors and it ended with “terminate called without an active exception”.

Setup:

  • Raspberry Pi 4
  • IMX519 camera
  • Latest Raspberry Pi OS (fresh install, then followed the installation steps)
  • Installed libcamera_dev, libcamera_apps, imx519_kernel_driver and the focus adjustment software

Install steps I followed:

wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps
./install_pivariety_pkgs.sh -p imx519_kernel_driver
git clone https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver.git

Then rebooted the Pi.

I’ve tried a one-time autofocus (libcamera-still -t 5000 -o test.jpg --autofocus) and the manual focus steps, but the image never comes into focus. Any ideas on how to get this camera to focus?

Thanks for the detailed write-up, that helps a lot. The “terminate called without an active exception” on the plain capture is worth digging into first, since it usually means the camera driver isn’t fully configuring.

Can you run a plain capture and paste the full console output here?

libcamera-still -t 5000 -o test.jpg

Also, while you’re at it, run this in a terminal with a preview window and watch the image while the autofocus runs:

libcamera-still -t 0 --autofocus

Let me know if the image changes at all during that, and paste the output from the first command.

Here’s the output from libcamera-still -t 5000 -o test.jpg:

[14:34:08.557282150] [5956]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3139-5baab39e
[14:34:08.561037614] [5959]  WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for 'imx519'
[14:34:08.561100649] [5959]  WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[14:34:08.577463713] [5959] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/video0
[14:34:08.577527322] [5959] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009e0901 but control is not exposed by device /dev/video0
[14:34:08.577557544] [5959] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x00980911 but control is not exposed by device /dev/video0
[14:34:08.577586173] [5959] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009e0903 but control is not exposed by device /dev/video0
[14:34:08.578655091] [5956]  INFO Camera camera.cpp:937 configuring streams: (0) 2328x1748-YUV420
[14:34:08.580971127] [5959]  INFO RPI raspberrypi.cpp:624 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected mode: 2328x1748-pgCC
[14:34:08.582339446] [5959] ERROR IPARPI raspberrypi.cpp:546 Unable to find sensor control 0x009e0903
[14:34:08.582398592] [5959] ERROR IPARPI raspberrypi.cpp:358 Sensor control validation failed.
[14:34:08.582436888] [5959] ERROR RPI raspberrypi.cpp:1353 IPA configuration failed!
[14:34:08.582475220] [5959] ERROR RPI raspberrypi.cpp:761 Failed to configure the IPA: -32
terminate called without an active exception

And on the libcamera-still -t 0 --autofocus preview, nothing appears to change. It seems to stay out of focus.

Should add - I installed the latest Raspberry Pi OS and re-ran the full installation steps again, but that didn’t change anything. Same behaviour as before.

Thanks. Those errors tell us a couple of things.

The WARN CameraSensorProperties ... No static properties available for 'imx519' lines are just informational - we know the sensor properties database may be behind, that won’t stop the camera working.

The important ones are these:

ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009e0903 but control is not exposed by device /dev/video0
ERROR IPARPI raspberrypi.cpp:546 Unable to find sensor control 0x009e0903
ERROR IPARPI raspberrypi.cpp:358 Sensor control validation failed.
ERROR RPI raspberrypi.cpp:1353 IPA configuration failed!
ERROR RPI raspberrypi.cpp:761 Failed to configure the IPA: -32

Control 0x009e0903 is the focus/autofocus control (focus absolute). The IPA is trying to configure it and the sensor isn’t exposing it, which is why the pipeline bails out. That lines up with you seeing no focus change at all.

Before we call it hardware though, let’s try the on-the-fly autofocus and the manual focus tool, to see if the VCM (voice coil motor) responds at all.

Step 1 - open a preview window:

libcamera-still -t 0

Step 2 - in another terminal, run the focus adjustment tool:

cd Arducam-Pivariety-V4L2-Driver/focus
python3 FocuserExample.py -d /dev/v4l-subdev1

Step 3 - press the Up/Down Arrow keys to adjust focus, then ctrl + c to save, or r to reset.

Watch the preview while you do that and tell me if the image sharpens at any point.

Ok so I ran the preview with libcamera-still -t 0 and then started the focus tool with python3 FocuserExample.py -d /dev/v4l-subdev1. I can step through with the arrow keys and it seems to accept them and run through the motions, but the preview image just doesn’t change - it stays soft/out of focus no matter where I set it. Pressing r to reset also doesn’t seem to do anything visible.

I also tried the autofocus command you suggested (libcamera-still -t 0 --autofocus) again and same thing, nothing appears to change. It really seems stuck out of focus.

Ok, that’s a really useful result. The key point is that the focus tool runs and accepts commands (so libcamera and the driver are talking to the sensor), but the lens position isn’t changing - the image stays soft both with autofocus and with manual adjustment. Combined with the 0x009e0903 / Failed to configure the IPA: -32 errors in the log, that points away from a software/config problem and towards a hardware fault in the focus mechanism (the VCM/lens assembly isn’t moving).

To be fair to the software side, we’ve now covered:

  • fresh Raspberry Pi OS + full driver/libcamera install
  • plain capture (see the IPA configuration failure)
  • one-time autofocus (libcamera-still -t 5000 -o test.jpg --autofocus)
  • live autofocus (libcamera-still -t 0 --autofocus)
  • manual focus via FocuserExample.py (commands accepted, no visible change)

Since none of those produce any change in focus, there isn’t a software workaround for this. This looks like a fault with the camera’s focus hardware itself. I’ve sent you a private message with the next steps so we can get this sorted for you - please check your messages.