IMX519 Autofocus and Picamera2

  1. Where did you get the camera module(s)?
  2. Model number of the product(s)?
    Arducam 16mp camera B0371
  3. What hardware/platform were you working on?
    Raspberry Pi Zero 2 W running Raspberry Pi OS (64 bit)
  4. Instructions you have followed. (link/manual/etc.)
    Picamera2 - Arducam Wiki
  5. Problems you were having?
    I cannot get the autofocus to work with picamera2. The picam2.set_controls({“AfTrigger”: 0}) code in the example appears to do nothing (the program just adds AfTrigger to the Controls dictionary). The autofocus works fine with a command such as “libcamera-still -t 0 --autofocus,” but it will not work with setting AfTrigger in picamera2. It appears that the latest version of picamera2 does not include the autofocus controls.
  6. The dmesg log from your hardware?
    [ 10.719088] imx519: loading out-of-tree module taints kernel.
    [ 10.755634] imx519 10-001a: Device found is imx519
    [ 10.756123] imx519 10-001a: Consider updating driver imx519 to match on endpoints
  7. Troubleshooting attempts you’ve made?
    I made sure the latest versions of picamera2 and other software are installed. I tried placing the AfTrigger command un different places in the code (e.g., before and after the start command). Picamera2 commands work fine otherwise.
  8. What help do you need?
    Is there a special version of picamera2 that includes the AfTrigger controls? I will appreciate any help or suggestions.

Please see the screenshot below:

You need to check if your libcamera version is 0.0.10:
dpkg -l | grep libcamera
If it shows 0.0.10, please modify the code:
picam2.set_controls({“AfMode”: 1 ,“AfTrigger”: 0})

1 Like

Why don’t you just update the documentation? It takes hours to figure out why autofocus doesn’t work. And then out of desperation accidentally find this post?

Thank you very much. That change appears to work.
Can a similar approach set continuous autofocus?
Perhaps you can publish the permissible values of AfMode and AfTrigger and what modes they set.

Hi fundix,
Oh boy, sorry for the bad experience. That’s really my fault.
I will add it to the Doc website.

Of course, you need to change the value of AFMod to 2.

We will add the documentation in the DOC website.

Thank you :slight_smile:

I generally struggle a lot with the camera and I think there were more changes.

Because in all the tutorials, the basic command libcamera-still -o demo.jpg library saves a 64Mpix photo. But the library only saves 16Mpix even if I choose -mode 9xxx:6xxx.

The only way to get 64Mpix was before python without autofocus. As soon as I turned on autofocus, the script froze on saving without any error.

If I used libcamera with -mode and -width the photo was just interpolated.

I tried all possible methods on Rpi 4b , 4G and 8G.

The 16mp is working brilliantly within Python3 on my 4b, but I am experiencing the same within python with the 64mp where it starts to autofocus and just locks up. If I do it from the command line with

libcamera-still --autofocus-mode auto -t 8000 -o test64.jpg

It takes an amazing picture that is focused properly, but only at 16mp. If I try and force the width/height to 64mp (9152 x 6944) I get an error
Unable to request 1 buffers: Cannot allocate memory
Followed by:
ERROR RPI raspberrypi.cpp:1069 Failed to allocate buffers
ERROR: *** failed to start camera ***

You can refer to the link below to configure your config file.

Thank you, but I already had that in my config.txt


You can take a look at another thread first.

You can try the solution proposed by the Raspberry Pi engineer. If it is still not resolved, I want to express my apologies to you. We still need to do more research on the cma part.

At present, 64mp still has many strange states, and we are also trying to understand which part of the problem is.

Prior to this post I did read and try everything that is listed in that thread and still am getting the issue. I have read every thread on these forums, and even found threads on other forums (by Arducam regarding CMA questions). I feel like this camera was never ready for the end user and now I’m stuck with two of them. I’ll keep monitoring these threads to see if the Arducam team ever gets this resolved, but I can’t hang hope and wishes on a product and sell it to the consumer.

The only way to save a 64Mpix photo is via python script. Otherwise it is not possible.