I have an esp32-cam with ov2640 and I simply want to take a still picture. When I do that with the CameraWebServer app it works fine. But from my code I'm getting an almost black picture. Some white spots appear so it may be a contrast problem.
I did a url/status call to CameraWebServer and got a dump of all the ov2640 settings. I then duplicated the code for that dump in my app and made sure my settings matched. Here are the settings ...
0xd3: 12
0x111: 0
0x132: 54
xclk: 20
pixformat: 4
framesize: 13
quality: 10
brightness: 0
contrast: 0
saturation: 0
sharpness: 0
special_effect: 0
wb_mode: 0
awb: 1
awb_gain: 1
aec: 1
aec2: 0
ae_level: 0
aec_value: 168
agc: 1
agc_gain: 0
gainceiling: 0
bpc: 0
wpc: 1
raw_gma: 1
lenc: 1
hmirror: 0
dcw: 1
colorbar: 0
Here is my code ...
void cameraSetup() {
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 = CAM_PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.jpeg_quality = 10;
config.fb_count = FB_COUNT;
// QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
config.frame_size = FRAMESIZE_UXGA;
// Init Camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
sensor_t * s = esp_camera_sensor_get();
s->set_brightness(s, 0); // -2 to 2
s->set_contrast(s, 0); // -2 to 2
s->set_saturation(s, 0); // -2 to 2
s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
s->set_whitebal(s, 1); // 0 = disable , 1 = enable
s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
s->set_wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_aec2(s, 0); // 0 = disable , 1 = enable
s->set_ae_level(s, 0); // -2 to 2
s->set_aec_value(s, 168); // 0 to 1200
s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_agc_gain(s, 0); // 0 to 30
s->set_gainceiling(s, (gainceiling_t)0); // 0 to 6
s->set_bpc(s, 0); // 0 = disable , 1 = enable
s->set_wpc(s, 1); // 0 = disable , 1 = enable
s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
s->set_lenc(s, 1); // 0 = disable , 1 = enable
s->set_hmirror(s, 0); // 0 = disable , 1 = enable
s->set_vflip(s, 0); // 0 = disable , 1 = enable
s->set_dcw(s, 1); // 0 = disable , 1 = enable
s->set_colorbar(s, 0); // 0 = disable , 1 = enable
}
camera_fb_t * getFrame() {
framebuf = esp_camera_fb_get();
if (!framebuf) {
Serial.println("Camera capture failed");
return nullptr;
}
Serial.printf("Captured frame, size %zu\n", framebuf->len);
return framebuf;
}
Other than picture problem the code works correctly. Is there something I need to set up other than these settings? Any ideas welcome.
