OV5640 Camera for XIAO ESP32S3 Sense - How to use Autofocus?

Hi - on April 3rd the driver was expected to be delivered in two weeks. What is the status on getting this driver completed?

I had some success with triggering the motor by following @PJ_Glasso’s example code and modifying it to work with the camera sensor’s internal functions for register access.

My system starts the camera, focuses, and takes a photo when triggered by a button.

#include <esp_camera.h>
#include <Arduino.h> // For Serial, delay

void ov5640_write_reg(sensor_t *s, uint16_t reg, uint8_t data) {
  // The s->set_reg function handles the SCCB/I2C communication.
  // The mask 0xFF means all 8 bits of 'data' will be written to the register.
  int res = s->set_reg(s, reg, 0xFF, data); 
}

void trigger_ov5640_autofocus(sensor_t *s) {
  // OV5640 Autofocus Register Sequence
  ov5640_write_reg(s, 0x3000, 0x20); // Enable/prepare autofocus system
  delay(10);
  ov5640_write_reg(s, 0x3000, 0x00); // Clear/reset autofocus bits
  delay(10);
  ov5640_write_reg(s, 0x3022, 0x08); // Command to start single-shot autofocus
  
  Serial.println("Waiting for autofocus to complete (500ms)...");
  delay(500);
  Serial.println("Autofocus sequence complete.");
}


camera_fb_t* takePhotoWithAutofocus() {
    sensor_t *s = esp_camera_sensor_get();

    trigger_ov5640_autofocus(s);

    Serial.println("Taking focused photo...");
    camera_fb_t *fb = esp_camera_fb_get();
    if (!fb) {
        Serial.println("❌ Camera capture failed!");
        return NULL;
    }

    Serial.println("Photo captured successfully.");
    
    return fb; 
}

After adding the autofocus code the OV5640 seems to get much hotter much faster, which is starting to affect the image quality (it’s possible this might be caused by something else in my code). Hope this helps! Would be great to get the official driver soon for a less hacky solution :slight_smile: