Changing the focus of the camera via python

  1. Where did you get the camera module(s)?
    Arducam website
  2. Model number of the product(s)?
    USB3 Camera Shield UC0593 Rev.C ( 108MP USB 3.0 Camera Evaluation Kit, Motorised Focus)
  3. What hardware/platform were you working on?
    Windows 10/python 3.10
  4. Instructions you have followed. (link/manual/etc.)
    ArduCAM_USB_Camera_Shield/Windows/Python/External_trigger_demo/ArduCam_Ext_Trigger_Demo.py at master · ArduCAM/ArduCAM_USB_Camera_Shield · GitHub
  5. Problems you were having?
    I want to change the focus via python. It works fine via the gui but i cant find documentation on how to do it in python.
  6. The dmesg log from your hardware?
    I don’t know what this means
  7. Troubleshooting attempts you’ve made?
    I read the example scripts but couldn’t find any documentation on this
  8. What help do you need?
    I would like to be able to set the focus via python.

Note, my python code for taking pictures is:
camera = Arducam.ArducamCamera()
camera.openCamera(config_file)
camera.start()
ret, data, cfg = camera.read()
image = ImageConvert.convert_image(data, cfg, camera.color_mode)
camera.stop()
camera.closeCamera()

@YuMu

The gui achieves various control effects by changing the configuration files, and you can change the related configuration files to achieve the effect.


image

1 Like

Dear Edward,

Thanks for the quick reply. I changed the number behind 'DEF = ’ in the code you took in your screenshot. If I then open the GUI it indeed opens the camera with the focus I set in the config file. However, changing this number does not change the pictures I take with my python script using the below script. Should this have changed my focus/any idea what I am doing wrong? I’ve double-checked and I am changing the right .cfg file which the python script also uses.

Best,

Yuval

camera = Arducam.ArducamCamera()
camera.openCamera(config_file)
camera.start()
ret, data, cfg = camera.read()
image = ImageConvert.convert_image(data, cfg, camera.color_mode)
camera.stop()
camera.closeCamera()

You don’t just have to change this.

You need to set the high and low bits of the following registers according to the DEF synchronization you set
image

Thanks again for the rapid response. I looked up on these registers but I still don’t understand them and can’t find much documentation. From what I understand, the final numbers are the ones I should change. How should I change them? e.g. could you give 2 examples of different DEF values and corresponding high and low bit registers?

@YuMu

As you can see in the calculation formula, 0x0300 represents the high bit, and 0x0400 represents the low bit.
image

The default DEF is 262, which is a decimal number. The value (hexadecimal) of the corresponding register should also be 262
image