Arducam_64mp autofocus via libcamera-still

Hi, thanks for the reply and instructions on how to move forward.
I did a fresh install of bullseye os: uname -a “5.15.84-v8+”
Ran sudo apt update & upgrade. I noticed it came with picamera2, installed libcamera through wget, then chmod +x, libcamera_dev, libcamera_apps, then ./installpivarietypkgs.sh -d. Tried it with sudo instead, and installed and it modified my config.txt. i remodified it so that the config has:

[pi4]
arm_boost=1
#dtoverlay=arducam_64mp
dtoverlay=vc4-kms-v3d,cma-512
[all]
dtparam=i2c_vc=on
dtparam=i2c_arm=on
dtoverlay=arducam64_mp

i also noticed that maybe picamera2 gets in the way of libcamera, or something like that because libcamera-still did not work after installing libcamera dev and apps. so i unistalled picamera2, with sudo apt remove python3-picamera2, then reinstalled 0.0.12 and libcamera-hello started to work.
i tried your code:

v4l2-ctl -l -d /dev/v4l-subdev1

and it returned:

Camera controls
                           focus_absolute 0x009a090a(int) : min=0 max=1023 step=1 default=0
 value=341

i also ran:

libcamera-still --autofocus-on-capture=1 --width 4624 --height 3472 --nopreview --output autofocus-on-capture-1-setWH.jpg

but, it returned a blurry pic.
i rebooted thinking maybe it needed a reboot, and ran the same code you sent, but it still returned a blurry pic.
I also tried on 0.0.10, but the pic stays blurry, too. I haven’t tried 0.0.11.
Would you suggest using picamera2 to change the AF or do i need libcamera to work first?

Thanks for the help.

I installed a brand new image. installed as per the pdf docs and it works as expected.

(I was using an older piOs image as the very latest was giving lots of errors when trying to follow the arducam instructions, something to do with Size)

Thanks!

@neezem_og

The most important thing is to ensure that libcamera can be used first.

Like @dot.dot , you can try to emulate him, make a fresh system use 5.15.84 + libcamera 0.0.12, and try again.

You can follow our tutorial webpage, do not use other methods on the Internet to ensure that the environment is clean enough
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Quick-Start-Guide/
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/PiCamera2-User-Guide/

@dot.dot

I am very happy to hear this news.

I also want to thank you for your cooperation, allowing us to increase our experience.

And use this thread as a common problem for future reference

I made a fresh system, using 5.15.84 + 0.0.12.
installed through quick start instructions, then went on to picamera2 instructions.
changed the AF from 0 to 1, but I got the error

[0:22:37.704336338][4162] WARN IPARPI raspberrypi.cpp:1192 Could not set AF_TRIGGER - no AF algorithm or not Auto

so, i ran libcamera-still --autofocus–mode auto, and set the picamera2 AF to 0, and i did the same thing for continuous, but set the AF to 1, but neither one returned a focused photo.

@neezem_og

Can you elaborate on that.

What code did you use to get the error below. (Please try to copy as complete as possible so that we can be in the same state)

What is the libcamera-still command output now, and is there any error you had before.

If possible, please give the specific command and the corresponding output.

The code I used is from the quick start instructions that you previously sent me to install libcamera and follow picamera2. the only difference was I used sudo on the libcamera instructions. For the picamera2 quick start instructions, i also used the link you gave me for instructions, and proceeded to do the example on thonny:

#!/usr/bin/python3
import time
from picamera2 import Picamera2, Preview
picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
preview_config = >picam2.create_preview_configuration()
picam2.configure(preview_config)
picam2.start()
time.sleep(1)
picam2.set_controls({“AfMode”: 1,“AfTrigger”: 0})
time.sleep(5)

I tried it again this morning, and i no longer get the error, but the picture is still blurry.
I then tried:

libcamera-still --autofocus-mode auto

and i didn’t get any errors, but the output is also blurry

i tried libcamera-hello, and i got this error:

[21:24:03.772132744] [9120] ERROR V4L2 v4l2_device.cpp:352 ‘dw9807 10-000c’: Unable to set controls: Input/output error

and i hadn’t seen that error before. :thinking: idk if it matters.

1 Like

Hi @neezem_og,

It is very strange that this problem occurs.

Can you give me the dmesg message after this error?

Also, have you tried manual focus and does it work?

I tried it again this morning, and I no longer get the error. But this is the dmesg that i did this morning without the error:

[74924.341995] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[74925.380311] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[74925.380327] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[74925.380349] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[74925.396684] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[74936.854583] w1_master_driver w1_bus_master1: Attaching one wire slave 00.786000000000 crc 60
[74936.858783] w1_master_driver w1_bus_master1: Family 0 for 00.786000000000.60 is not registered.
[74995.494585] w1_master_driver w1_bus_master1: Attaching one wire slave 00.f86000000000 crc ec
[74995.498773] w1_master_driver w1_bus_master1: Family 0 for 00.f86000000000.ec is not registered.
[75014.734025] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[75015.780343] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[75015.780376] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[75015.780421] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[75077.447124] w1_master_driver w1_bus_master1: Attaching one wire slave 00.046000000000 crc 3b
[75077.453507] w1_master_driver w1_bus_master1: Family 0 for 00.046000000000.3b is not registered.
[75125.058586] w1_master_driver w1_bus_master1: Attaching one wire slave 00.846000000000 crc b7
[75125.062774] w1_master_driver w1_bus_master1: Family 0 for 00.846000000000.b7 is not registered.
[75160.862585] w1_master_driver w1_bus_master1: Attaching one wire slave 00.446000000000 crc 7d
[75160.866780] w1_master_driver w1_bus_master1: Family 0 for 00.446000000000.7d is not registered.
[75206.935113] w1_master_driver w1_bus_master1: Attaching one wire slave 00.c46000000000 crc f1
[75206.944707] w1_master_driver w1_bus_master1: Family 0 for 00.c46000000000.f1 is not registered.
[75230.750595] w1_master_driver w1_bus_master1: Attaching one wire slave 00.246000000000 crc 18
[75230.754887] w1_master_driver w1_bus_master1: Family 0 for 00.246000000000.18 is not registered.
[75278.358597] w1_master_driver w1_bus_master1: Attaching one wire slave 00.a46000000000 crc 94
[75278.362813] w1_master_driver w1_bus_master1: Family 0 for 00.a46000000000.94 is not registered.
[75337.766587] w1_master_driver w1_bus_master1: Attaching one wire slave 00.646000000000 crc 5e
[75337.770829] w1_master_driver w1_bus_master1: Family 0 for 00.646000000000.5e is not registered.
[75383.838584] w1_master_driver w1_bus_master1: Attaching one wire slave 00.e46000000000 crc d2
[75383.842809] w1_master_driver w1_bus_master1: Family 0 for 00.e46000000000.d2 is not registered.
[75431.662585] w1_master_driver w1_bus_master1: Attaching one wire slave 00.146000000000 crc a6
[75431.666852] w1_master_driver w1_bus_master1: Family 0 for 00.146000000000.a6 is not registered.
[75478.454580] w1_master_driver w1_bus_master1: Attaching one wire slave 00.946000000000 crc 2a
[75478.458734] w1_master_driver w1_bus_master1: Family 0 for 00.946000000000.2a is not registered.
[75513.542594] w1_master_driver w1_bus_master1: Attaching one wire slave 00.546000000000 crc e0
[75513.546858] w1_master_driver w1_bus_master1: Family 0 for 00.546000000000.e0 is not registered.
[75572.134584] w1_master_driver w1_bus_master1: Attaching one wire slave 00.d46000000000 crc 6c
[75572.138782] w1_master_driver w1_bus_master1: Family 0 for 00.d46000000000.6c is not registered.
[75632.166579] w1_master_driver w1_bus_master1: Attaching one wire slave 00.346000000000 crc 85
[75632.170799] w1_master_driver w1_bus_master1: Family 0 for 00.346000000000.85 is not registered.
[75678.958584] w1_master_driver w1_bus_master1: Attaching one wire slave 00.b46000000000 crc 09
[75678.962765] w1_master_driver w1_bus_master1: Family 0 for 00.b46000000000.09 is not registered.
[75737.646579] w1_master_driver w1_bus_master1: Attaching one wire slave 00.746000000000 crc c3
[75737.650720] w1_master_driver w1_bus_master1: Family 0 for 00.746000000000.c3 is not registered.
[75796.238584] w1_master_driver w1_bus_master1: Attaching one wire slave 00.f46000000000 crc 4f
[75796.242755] w1_master_driver w1_bus_master1: Family 0 for 00.f46000000000.4f is not registered.
[75811.289934] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[75812.324302] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[75812.324317] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[75812.324337] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[75812.344630] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[75831.182742] w1_master_driver w1_bus_master1: Attaching one wire slave 00.0c6000000000 crc f9
[75831.188105] w1_master_driver w1_bus_master1: Family 0 for 00.0c6000000000.f9 is not registered.
[75878.742583] w1_master_driver w1_bus_master1: Attaching one wire slave 00.8c6000000000 crc 75
[75878.746775] w1_master_driver w1_bus_master1: Family 0 for 00.8c6000000000.75 is not registered.
[75938.102578] w1_master_driver w1_bus_master1: Attaching one wire slave 00.4c6000000000 crc bf
[75938.106762] w1_master_driver w1_bus_master1: Family 0 for 00.4c6000000000.bf is not registered.
[75973.862585] w1_master_driver w1_bus_master1: Attaching one wire slave 00.cc6000000000 crc 33
[75973.866810] w1_master_driver w1_bus_master1: Family 0 for 00.cc6000000000.33 is not registered.
[76008.086593] w1_master_driver w1_bus_master1: Attaching one wire slave 00.2c6000000000 crc da
[76008.090770] w1_master_driver w1_bus_master1: Family 0 for 00.2c6000000000.da is not registered.
[76040.509992] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[76041.540350] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[76041.540385] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[76041.540429] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[76055.646583] w1_master_driver w1_bus_master1: Attaching one wire slave 00.ac6000000000 crc 56
[76055.650735] w1_master_driver w1_bus_master1: Family 0 for 00.ac6000000000.56 is not registered.
[76091.406607] w1_master_driver w1_bus_master1: Attaching one wire slave 00.6c6000000000 crc 9c
[76091.410760] w1_master_driver w1_bus_master1: Family 0 for 00.6c6000000000.9c is not registered.
[76137.430587] w1_master_driver w1_bus_master1: Attaching one wire slave 00.ec6000000000 crc 10
[76137.434844] w1_master_driver w1_bus_master1: Family 0 for 00.ec6000000000.10 is not registered.
[76155.773998] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[76156.804371] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[76156.804404] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[76156.804469] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[76185.350585] w1_master_driver w1_bus_master1: Attaching one wire slave 00.1c6000000000 crc 64
[76185.354793] w1_master_driver w1_bus_master1: Family 0 for 00.1c6000000000.64 is not registered.
[76232.190577] w1_master_driver w1_bus_master1: Attaching one wire slave 00.9c6000000000 crc e8
[76232.194757] w1_master_driver w1_bus_master1: Family 0 for 00.9c6000000000.e8 is not registered.
[76245.521758] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[76246.564306] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[76246.564324] edt_ft5x06 10-0038: Unable to fetch data, error: -110
[76246.564350] edt_ft5x06 10-0038: Unable to fetch data, error: -5
[76290.734583] w1_master_driver w1_bus_master1: Attaching one wire slave 00.5c6000000000 crc 22
[76290.738794] w1_master_driver w1_bus_master1: Family 0 for 00.5c6000000000.22 is not registered.
[76349.375059] w1_master_driver w1_bus_master1: Attaching one wire slave 00.dc6000000000 crc ae
[76349.381194] w1_master_driver w1_bus_master1: Family 0 for 00.dc6000000000.ae is not registered.

it is much longer than that, and takes up the terminal, but it repeats these lines.

i am going to reboot the pi, and try autofocus, continuous, then the link you sent to try manual now. I will reply how it goes.

Ok, I ran both the autofocus and continuous, but it was still blurry, so I tried the manual focus, and I was able to get this error:

Traceback (most recent call last):
File “/home/pi/Desktop/v4l2_utils.py”, line 64, in get_device_controls_by_class
fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCTRL, queryctrl)
OSError: [Errno 25] Inappropriate ioctl for device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/pi/Desktop/focuser.py”, line 86, in
test()
File “/home/pi/Desktop/focuser.py”, line 78, in test
focuser = Focuser(0)
File “/home/pi/Desktop/focuser.py”, line 16, in init
self.ctrls = v4l2_utils.get_ctrls(self.fd)
File “/home/pi/Desktop/v4l2_utils.py”, line 96, in get_ctrls
for queryctrl in get_device_controls_by_class(vd, class_):
File “/home/pi/Desktop/v4l2_utils.py”, line 66, in get_device_controls_by_class
assert e.errno == errno.EINVAL
AssertionError

@neezem_og

I forgot to tell you that you need to add parameters, sorry

python3 FocuserExample.py -d /dev/v4l-subdev1

This is what I get, but I’m not entirely sure where to go from here? Running the “libcamera-still --autofocus-mode auto” still returns blurry. Running “libcamera-still --autofocus-mode manual” also returns blurry …

1 Like

@neezem_og

You need to open and then open a window, then use the following command

libcamera-still -t 0

Then return to this control page and use the keyboard controls to manually adjust the focus. Observe whether the previewed image changes.

I want to apologize to you, I noticed that there is a lack of documentation on this part, so I will improve this documentation later on our documentation website.

Had similar issues as in this thread, and nothing helped. Then I realized I had mounted the camera into a raspberry case for an older camera which had a smaller hole for the camera lens and pushed it in a way that the autofocus couldn’t move.

Just as a reference if anyone else experience similar issues.

Hi my friend . i have the same issue . your image still blurry ?

Hi edward . i have a problem in using imx519 camera
when i run the libcamera test command ( libcamera-still -t 1000 -o test.jpg )
i will get a nice and focused image with no blurry .
but when i use picamera2 to get my image in python app i will get blurry image and this warning :

( WARN IPARPI ipa_base.cpp:1081 Could not set AF_TRIGGER - no AF algorithm or not Auto )

my code :

import cv2
import argparse
import os
from picamera2 import Picamera2

# Parse command-line arguments
parser = argparse.ArgumentParser(description='Camera Recorder')
parser.add_argument('--image-size-w', required=True, type=int, help='Image resolution')
parser.add_argument('--image-size-h', required=True, type=int, help='Image resolution')
parser.add_argument('--save', type=str, required=True, help='Output folder name')
args = parser.parse_args()

# Create output folder if it doesn't exist
if not os.path.exists(args.save):
    os.makedirs(args.save)
else:
    # If the folder already exists, append a number to the end
    i = 1
    while os.path.exists(args.save + '_' + str(i)):
        i += 1
    args.save += '_' + str(i)
    os.makedirs(args.save)

picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (args.image_size_w, args.image_size_h)}))
picam2.start()
picam2.set_controls({"AfMode": 2, "AfTrigger": 0})
image_saver_counter = 0
frame_counter = 0
skip_frames = 6

print(f'\n\n Saving images in the : {args.save} \n\n')
while True:
    im = picam2.capture_array()
    
    if frame_counter % skip_frames == 0:
        save_path = os.path.join(args.save, f"image{args.image_size_w}_{args.image_size_h}_{image_saver_counter}.jpg")
        cv2.imwrite(save_path, im)
        image_saver_counter += 1
    
    frame_counter += 1

Hi @Edward I also get this same warning and a blurry photo with picam2 arducam 64mp and bookworm on a rpi4