IMX519 focus and config.txt path issues on Raspberry Pi bullseye/bookworm

Hi, we’re setting up a batch of 100 IMX519 cameras and I can’t get consistent focus across the units. The plan is to scale to tens of thousands eventually, so I need this to be repeatable. Two things are confusing me right now: I’m not sure whether I should be on bullseye or bookworm, and the install_pivariety_pkgs.sh script still tells me to edit /boot/config.txt, but everything else points to /boot/firmware/config.txt. Are we supposed to use that script as-is? I’m also looking for recommended settings or calibration steps, any firmware/software adjustments, and troubleshooting steps to get consistent focus across multiple units.

A few things to narrow this down first: which Raspberry Pi model are these running on, and which OS/kernel are the cameras on right now? Could you run the Arducam bug report script and attach the output? The /boot/config.txt vs /boot/firmware/config.txt note in that script is a known legacy thing, but let’s first confirm the camera stack itself is installed correctly.

Right now the units are Raspberry Pi boards running bullseye or bookworm with the IMX519 driver. I’ve attached the output from the bug report script here: arducam-bug-report.txt. The script I was digging into is ./install_pivariety_pkgs.sh, and the mismatch is the /boot/config.txt vs /boot/firmware/config.txt reference.

Thanks, the report looks okay. The focus motor on the IMX519 is not damaged and the Arducam custom libcamera stack is installed correctly. The IMX519 supports autofocus by default and these units are tested before shipping. The blurriness you’re seeing is likely because the lens hasn’t had strict factory calibration, so manual focus mode may not line up with the inverse distance relationship described in the Picamera2 Manual. The report also shows these are Pi Zero boards, and the Pi Zero’s limited performance can restrict what the camera is able to do.

For now, I’d suggest using autofocus mode and letting the camera self-adjust. If you do need manual focus, use keyboard adjustments to tune --lens-position dynamically. Bullseye with kernel 6.1.21 is the recommended OS for full PDAF support, and a Raspberry Pi 4 is strongly recommended. No additional firmware updates are needed.

Manual focus example: libcamera-vid --autofocus-mode manual --lens-position X
Full autofocus example: libcamera-still -t 0
Keyboard control reference: libcamera and rpicam-apps - Arducam Wiki

Also ignore that script’s reference to editing /boot/config.txt, it’s a legacy note. From the Picamera2 Manual: ‘The minimum value of X for the lens position is typically 0.0 (infinity). A maximum value of 10.0 corresponds to a closest focus distance of 10cm. Default values are often between 0.5-1.0 (hyperfocal distance ~1-2m).’

Thanks. So the cameras are installed inside a 200mm x 200mm x 200mm black box designed for UV image capture. The setup has to take images under both white light and UV light. Under white light the images are still very blurry, so autofocus doesn’t seem to be working optimally in this setup. I’m wondering if the enclosed environment or UV-reflective surfaces are interfering with autofocus since it relies on contrast and lighting. Would manually adjusting the lens position with --lens-position be more effective here? Could an external IR-cut filter or some lens modification help when switching between white and UV light? And would upgrading to a Raspberry Pi 4 actually improve autofocus stability?

Given the controlled black box with white and UV lighting, manual lens calibration is probably going to be more effective than relying on autofocus. Autofocus depends heavily on contrast and lighting conditions, and an enclosed box with UV-reflective surfaces can interfere with it. The Pi Zero also tends to add autofocus latency or just fail to converge in complex setups.

I’d recommend manual --lens-position tuning plus keyboard control for focus, and upgrading to a Raspberry Pi 4 is strongly recommended. For external IR-cut filters or lens modifications for UV work, that’s more of a custom imaging question, so you’d want to contact Arducam sales for custom UV imaging solutions.

That makes sense. Could you walk me through the manual calibration steps? And how exactly do the keyboard controls for focus work?

Sure. First, test fixed lens positions. Use the --lens-position parameter in libcamera commands to set focus manually, for example: libcamera-still --autofocus-mode manual --lens-position 0.5 -o test.jpg. Then test incremental positions like 0.3, 0.5, and 0.7 under both white and UV light. To judge sharpness, use a high-contrast test chart such as USAF 1951 and an image analysis tool like Imatest to find the optimal position.

For a calibration workflow: place a test chart like USAF 1951 inside the box, capture images at incremental lens positions under both white and UV light, then analyze the results to find the position with the best sharpness.

For keyboard control: run libcamera-still -t 0 --autofocus-mode manual -k to enter preview mode. In the libcamera log window, f + Enter triggers single-shot autofocus, a + Enter increments the lens position by 1 unit, and d + Enter decrements the lens position by 1 unit. So type a or d followed by Enter to fine-tune focus, and f followed by Enter when you want a quick autofocus run.

That’s clear, thanks. One last thing: how much does the Raspberry Pi 4 actually help with autofocus in a low-contrast box like this, and is bullseye still the right choice for PDAF?

The Pi 4 helps quite a bit. Its faster CPU and GPU improve autofocus stability, especially in low-light or low-contrast environments like your black box. Bullseye with kernel 6.1.21+ and the Arducam custom libcamera enables Phase Detection Autofocus (PDAF), which significantly speeds up focus convergence. The Pi Zero’s limited resources are the main reason autofocus gets slow or fails in these controlled setups.

So the current conclusion is: stay on bullseye, move to a Raspberry Pi 4 if you can, and inside the box rely on manual --lens-position calibration with the keyboard controls rather than depending on autofocus.