Arduino build error

fatal error: esp_camera.h: No such file or directory

esp_camera.h is the camera driver of the ESP32 board package. It exists for ESP32 boards, such as the ESP32-CAM, and for nothing else.

  • Build error
  • 2 common causes
The message

What the Arduino IDE prints

Output window
sketch.ino:1:10: fatal error: esp_camera.h: No such file or directory
    1 | #include <esp_camera.h>
      |          ^~~~~~~~~~
compilation terminated.
exit status 1

On an Uno, an ESP8266 or a missing board package, the file is not there.

Mokxi's compiler, clang, words it as 'esp_camera.h' file not found.

Causes

The 2 usual causes with the fix

1The board is not an ESP32

Choose an ESP32 board. For the AI Thinker ESP32-CAM, pick that board by name. Mokxi draws the camera but does not simulate an image: esp_camera_init() fails with ESP_ERR_NOT_FOUND, so your own failure path runs.

Broken
#include "esp_camera.h"

void setup() {
  Serial.begin(9600);
}

void loop() {
}
Fixed
#include "esp_camera.h"

void setup() {
  Serial.begin(115200);
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = 5;
  config.pin_d1 = 18;
  config.pin_d2 = 19;
  config.pin_d3 = 21;
  config.pin_d4 = 36;
  config.pin_d5 = 39;
  config.pin_d6 = 34;
  config.pin_d7 = 35;
  config.pin_xclk = 0;
  config.pin_pclk = 22;
  config.pin_vsync = 25;
  config.pin_href = 23;
  config.pin_sccb_sda = 26;
  config.pin_sccb_scl = 27;
  config.pin_pwdn = 32;
  config.pin_reset = -1;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  config.frame_size = FRAMESIZE_QVGA;
  config.jpeg_quality = 12;
  config.fb_count = 1;
  config.fb_location = CAMERA_FB_IN_DRAM;
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.sccb_i2c_port = 0;

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x\n", err);
    return;
  }
  Serial.println("camera ready");
}

void loop() {
}

Mokxi’s build tab says: Pick an ESP32 board

Try this fix in Mokxi

2The ESP32 board package is not installed

The camera driver comes with the ESP32 package, not with the Arduino IDE. Install it once.

  1. In the Arduino IDE, open File, Preferences, and add the ESP32 package URL under Additional boards manager URLs.
  2. Open Tools, Board, Boards Manager, search for esp32, and install the one by Espressif Systems.
  3. Pick your ESP32 board under Tools, Board, then compile again.
FAQ

Questions and answers

Does the camera work in Mokxi?

The camera is drawn, but nothing simulates an image. esp_camera_init() reports that no camera answered, so you can test the rest of the sketch.

Which boards have esp_camera.h?

ESP32 boards with a camera port, such as the AI Thinker ESP32-CAM and the ESP32-S3 camera boards.

Why does the ESP32-CAM need a special board setting?

The camera pins differ between boards. Pick the board that matches yours, or set the pins in camera_config_t.