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

HI PJ… Haha we must be because with a little help from ChatGPT wrote:

void setAutoFocus(sensor_t *s, uint16_t focusValue) {
if (focusValue > 1023) focusValue = 1023;

uint8_t high = (focusValue >> 8) & 0x03;
uint8_t low = focusValue & 0xFF;

ov5640_write_reg(s, 0x3022, 0x00); // Pause AF
ov5640_write_reg(s, 0x3023, high); // High byte
ov5640_write_reg(s, 0x3024, low); // Low byte
ov5640_write_reg(s, 0x3022, 0x06); // Trigger manual focus

Serial.printf(“Set manual focus to: %d\n”, focusValue);
}

Still working on refining this, and will compare to what you have done.

Great work :+1:
kc

1 Like