Arducam IMX219 motorized focus preview window unavailable on Raspberry Pi Zero W

Hi, I’m stuck with my Arducam 8MP IMX219 camera on a Pi Zero W. I’m trying to use the motorized focus feature from the IMX219 Motorized Focus Camera Quick Start Guide, but whenever I run the ‘Manual focus’ code the preview window just closes abruptly. libcamera-hello also returns ‘Preview window unavailable’. At first the camera didn’t seem to work at all - I couldn’t get it to connect to a display with the Pi Zero. Anyone run into this?

Thanks for the details. One thing to note right away: the camera you’re using is not an autofocus module, but let’s work through the setup first and see what’s going on. Can you tell me a bit more about your environment? Which OS image are you running, and how are you connecting to the Pi for the preview?

Sure. It’s a Raspberry Pi Zero W running Raspberry Pi OS Legacy 32-bit (Bullseye 11, the 2024-03-12 image). Camera is an Arducam 8MP IMX219, wired up per the connection diagram. I’m connecting over SSH and trying to get the preview through X11 forwarding with Xming in PuTTY, and I’ve also tried RealVNC. I followed the Arducam native camera Quick Start Guide for Bullseye/Bookworm and installed the libcamera-apps package.

Got it. Can you check your /boot/config.txt and confirm the IMX219 overlay is present? Run sudo nano /boot/config.txt, add dtoverlay=imx219 under the [all] section at the bottom, then reboot the Pi.

I added the overlay under [all] and rebooted. Here’s the line I put in: dtoverlay=imx2019. Still no luck though.

There’s a typo in there - it needs to be imx219, not imx2019. Can you fix that line, save the file, and reboot again?

Ah, good catch. I fixed that. Then I followed the Motorized Focus guide - I changed the overlay to dtoverlay=imx219, vcm and removed camera_auto_detect=1 from config.txt. After that I ran sudo apt-get update, sudo apt-get dist-upgrade, and sudo reboot.

Just double-checking - the overlay line should be dtoverlay=imx219,vcm with the correct imx219 spelling. If that’s in place, try testing with libcamera-hello and let me know exactly what you see.

I actually wrote it as imx2019,vcm again in the config, so I’ll fix that now. After fixing, I ran libcamera-hello and the camera seems to be detected now, but the preview still won’t show. When I run the Manual focus code the preview window terminates abruptly. I’m previewing over SSH with X11 forwarding/Xming and also tried RealVNC.

Since you’re over SSH without a local monitor, try these instead: for preview use libcamera-still -t 0 --qt-preview, and for a test capture use libcamera-still -t 5000 -o test.jpg -n. Can you run those and paste back the output?

Here’s the log from libcamera:
“Preview window unavailable”
[0:01:40.357186000] [864] INFO Camera camera_manager.cpp:297 libcamera v0.0.0+4367-ad9428b4
[0:01:41.018363000] [930] WARN RPI vc4.cpp:390 Mismatch between Unicam and CamHelper for embedded data usage!
[0:01:41.033960000] [930] INFO RPI vc4.cpp:444 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media0
[0:01:41.039855000] [930] INFO RPI pipeline_base.cpp:1101 Using configuration file ‘/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml’
[0:01:41.045436000] [864] INFO Camera camera.cpp:1033 configuring streams: (0) 1640x1232-YUV420
[0:01:41.057240000] [930] INFO RPI vc4.cpp:572 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1640x1232-SBGGR10_1X10 - Selected unicam format: 1640x1232-pBAA
#0 (0.00 fps) exp 12570.00 ag 2.00 dg 1.29
#1 (15.00 fps) exp 12570.00 ag 2.00 dg 1.29
#2 (15.00 fps) exp 12570.00 ag 2.00 dg 1.29
#3 (30.01 fps) exp 16181.00 ag 2.00 dg 1.00
#4 (7.50 fps) exp 16181.00 ag 2.00 dg 1.00
#5 (15.00 fps) exp 16162.00 ag 2.00 dg 1.00
#6 (15.00 fps) exp 16162.00 ag 2.00 dg 1.00

Thanks, that log is actually good news in one way - the framerate/exposure/gain values are updating normally, which means the camera itself is streaming fine. The ‘Preview window unavailable’ message is expected when you’re controlling the Pi over SSH without a monitor attached; the preview window can’t be created on a display that isn’t there. That part is separate from the focus issue though.

That makes sense for the preview. My main goal is to build an insect/plant camera trap and remotely adjust the focus onto the target plant over SSH, without having to open the protective/waterproof case. So I really need the motorized focus to work remotely.

I took a closer look at the module you have. The B039001 IMX219 is a fixed-focus module - it doesn’t have autofocus or a motorized lens, so the motorized focus feature simply isn’t available on this hardware. That’s why the Manual focus code can’t work no matter how the config is set up.

To get the motorized focus feature you’d need the Arducam Raspberry Pi Camera 8MP IMX219 Auto Focus Camera Module with the motorized lens - I’ve sent you the product link in a private message. As a recap, your current config should have dtoverlay=imx219 under [all] in /boot/config.txt, preview with libcamera-still -t 0 --qt-preview, and capture with libcamera-still -t 5000 -o test.jpg -n. But keep in mind the fixed-focus module won’t do motorized focus - that’s a hardware limitation of the B039001.