Help with OV7670 Camera on ESP32 - SCCB Communication Error

Hi everyone,

I'm working on a project that involves connecting an OV7670 camera module (without FIFO) to an ESP32 board. However, I'm running into an issue with the SCCB (I2C) communication. Here's the issue I'm facing:

Symptoms:

During initialization, I get the following output on the Serial Monitor:


14:57:41.793 -> --- Starting Camera Diagnostics ---
14:57:41.793 -> Step 1: Verifying Pin Configuration...
14:57:41.793 -> Pin configuration looks good!
14:57:41.793 -> Step 2: Checking SCCB Communication...
14:57:41.793 -> Testing SCCB...
14:57:41.793 -> SCCB test failed with error code: 2
14:57:41.793 -> Error: SCCB (I2C) communication failed. Check SIOD/SIOC  connections and pull-up resistors.

Here is my code, that i found and edited a bit with the help of AI:

#include "esp_camera.h"
#include "Wire.h"

#define PWDN_GPIO_NUM     17
#define RESET_GPIO_NUM    16
#define XCLK_GPIO_NUM     19
#define SIOD_GPIO_NUM     21
#define SIOC_GPIO_NUM     22

#define Y9_GPIO_NUM       32
#define Y8_GPIO_NUM       33
#define Y7_GPIO_NUM       35
#define Y6_GPIO_NUM       34
#define Y5_GPIO_NUM       14
#define Y4_GPIO_NUM       26
#define Y3_GPIO_NUM        2
#define Y2_GPIO_NUM        4

#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     18

void setup() {
  Serial.begin(115200);
  delay(1000);

  pinMode(SIOD_GPIO_NUM, INPUT_PULLUP); 
  pinMode(SIOC_GPIO_NUM, INPUT_PULLUP); 

  Serial.println("\n--- Starting Camera Diagnostics ---");

  // Step 1: Verify Pin Configuration
  Serial.println("Step 1: Verifying Pin Configuration...");
  bool pinConfigOk = true;
  if (XCLK_GPIO_NUM == -1 || PCLK_GPIO_NUM == -1) {
    Serial.println("Error: Clock pins not set properly.");
    pinConfigOk = false;
  }
  if (!pinConfigOk) {
    Serial.println("Pin configuration failed. Check your wiring.");
    while (true); 
  } else {
    Serial.println("Pin configuration looks good!");
  }

  Serial.println("Step 2: Checking SCCB Communication...");
  if (!testSCCB()) {
    Serial.println("Error: SCCB (I2C) communication failed. Check SIOD/SIOC connections and pull-up resistors.");
    while (true); 
  } else {
    Serial.println("SCCB communication successful!");
  }

  Serial.println("Step 3: Configuring Camera...");
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_RGB565; // Adjust if necessary
  config.frame_size = FRAMESIZE_QVGA;     // Use small size for testing
  config.fb_count = 1;

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x\n", err);
    checkErrorCode(err); 
    while (true); 
  } else {
    Serial.println("Camera successfully initialized!");
  }

  
  Serial.println("Step 4: Testing Frame Capture...");
  camera_fb_t *fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("Error: Failed to capture a frame.");
    while (true); 
  } else {
    Serial.printf("Frame captured successfully! Size: %d bytes\n", fb->len);
    esp_camera_fb_return(fb);
  }

  Serial.println("--- Camera Diagnostics Complete ---");
}

void loop() {
  // Frame capture test in the loop
  camera_fb_t *fb = esp_camera_fb_get();
  if (fb) {
    Serial.println("Frame capture succeeded in loop!");
    esp_camera_fb_return(fb);
  } else {
    Serial.println("Error: Frame capture failed in loop.");
  }
  delay(2000);
}

bool testSCCB() {
  Serial.println("Testing SCCB...");
  uint8_t addr = 0x42 >> 1;
  Wire.begin(SIOD_GPIO_NUM, SIOC_GPIO_NUM); 
  Wire.beginTransmission(addr);
  uint8_t error = Wire.endTransmission();
  if (error == 0) {
    Serial.println("SCCB test passed!");
    return true;
  } else {
    Serial.printf("SCCB test failed with error code: %d\n", error);
    return false;
  }
}

void checkErrorCode(esp_err_t err) {
  switch (err) {
    case ESP_ERR_NO_MEM:
      Serial.println("Error: Out of memory.");
      break;
    case ESP_ERR_INVALID_ARG:
      Serial.println("Error: Invalid argument.");
      break;
    case ESP_ERR_INVALID_STATE:
      Serial.println("Error: Invalid state.");
      break;
    case ESP_ERR_NOT_FOUND:
      Serial.println("Error: Requested resource not found.");
      break;
    case ESP_ERR_NOT_SUPPORTED:
      Serial.println("Error: Operation not supported.");
      break;
    default:
      Serial.printf("Unknown error: 0x%x\n", err);
  }
}

I would really appreciate any insights or suggestions on how to troubleshoot or resolve this issue. Thanks in advance for your help!

Your topic does not indicate a problem with the IDE and hence has been moved.

Thanks for using code tags in your first post :+1:

Thank you!