Skip to content

fix(example): led flash not working if not using default model in camera example. #11466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
#include "esp_camera.h"
#include <WiFi.h>

//
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
// Partial images will be transmitted if image exceeds buffer size
//
// You must select partition scheme from the board menu that has at least 3MB APP space.
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well

// ===================
// Select camera model
// ===================
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
#include "camera_pins.h"
// ===========================
// Select camera model in board_config.h
// ===========================
#include "board_config.h"

// ===========================
// Enter your WiFi credentials
Expand All @@ -40,7 +13,7 @@ const char *ssid = "**********";
const char *password = "**********";

void startCameraServer();
void setupLedFlash(int pin);
void setupLedFlash();

void setup() {
Serial.begin(115200);
Expand Down Expand Up @@ -130,7 +103,7 @@ void setup() {

// Setup LED FLash if LED pin is defined in camera_pins.h
#if defined(LED_GPIO_NUM)
setupLedFlash(LED_GPIO_NUM);
setupLedFlash();
#endif

WiFi.begin(ssid, password);
Expand Down
30 changes: 13 additions & 17 deletions libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
#include "esp32-hal-ledc.h"
#include "sdkconfig.h"
#include "camera_index.h"
#include "board_config.h"

#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#endif

// Enable LED FLASH setting
#define CONFIG_LED_ILLUMINATOR_ENABLED 1

// LED FLASH setup
#if CONFIG_LED_ILLUMINATOR_ENABLED

#define LED_LEDC_GPIO 22 //configure LED pin
#if defined(LED_GPIO_NUM)
#define CONFIG_LED_MAX_INTENSITY 255

int led_duty = 0;
Expand Down Expand Up @@ -91,13 +87,13 @@ static int ra_filter_run(ra_filter_t *filter, int value) {
}
#endif

#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
void enable_led(bool en) { // Turn LED On or Off
int duty = en ? led_duty : 0;
if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)) {
duty = CONFIG_LED_MAX_INTENSITY;
}
ledcWrite(LED_LEDC_GPIO, duty);
ledcWrite(LED_GPIO_NUM, duty);
//ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty);
//ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL);
log_i("Set LED intensity to %d", duty);
Expand Down Expand Up @@ -162,7 +158,7 @@ static esp_err_t capture_handler(httpd_req_t *req) {
int64_t fr_start = esp_timer_get_time();
#endif

#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
enable_led(true);
vTaskDelay(150 / portTICK_PERIOD_MS); // The LED needs to be turned on ~150ms before the call to esp_camera_fb_get()
fb = esp_camera_fb_get(); // or it won't be visible in the frame. A better way to do this is needed.
Expand Down Expand Up @@ -230,7 +226,7 @@ static esp_err_t stream_handler(httpd_req_t *req) {
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_hdr(req, "X-Framerate", "60");

#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
isStreaming = true;
enable_led(true);
#endif
Expand Down Expand Up @@ -293,7 +289,7 @@ static esp_err_t stream_handler(httpd_req_t *req) {
);
}

#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
isStreaming = false;
enable_led(false);
#endif
Expand Down Expand Up @@ -393,7 +389,7 @@ static esp_err_t cmd_handler(httpd_req_t *req) {
} else if (!strcmp(variable, "ae_level")) {
res = s->set_ae_level(s, val);
}
#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
else if (!strcmp(variable, "led_intensity")) {
led_duty = val;
if (isStreaming) {
Expand Down Expand Up @@ -481,7 +477,7 @@ static esp_err_t status_handler(httpd_req_t *req) {
p += sprintf(p, "\"vflip\":%u,", s->status.vflip);
p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
#if CONFIG_LED_ILLUMINATOR_ENABLED
#if defined(LED_GPIO_NUM)
p += sprintf(p, ",\"led_intensity\":%u", led_duty);
#else
p += sprintf(p, ",\"led_intensity\":%d", -1);
Expand Down Expand Up @@ -843,10 +839,10 @@ void startCameraServer() {
}
}

void setupLedFlash(int pin) {
#if CONFIG_LED_ILLUMINATOR_ENABLED
ledcAttach(pin, 5000, 8);
void setupLedFlash() {
#if defined(LED_GPIO_NUM)
ledcAttach(LED_GPIO_NUM, 5000, 8);
#else
log_i("LED flash is disabled -> CONFIG_LED_ILLUMINATOR_ENABLED = 0");
log_i("LED flash is disabled -> LED_GPIO_NUM undefined");
#endif
}
27 changes: 27 additions & 0 deletions libraries/ESP32/examples/Camera/CameraWebServer/board_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
// Partial images will be transmitted if image exceeds buffer size
//
// You must select partition scheme from the board menu that has at least 3MB APP space.
// ===================
// Select camera model
// ===================
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
#include "camera_pins.h"