Skip to content

Update camera example for support LED Intensity #6791

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 21 additions & 19 deletions libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#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
Expand All @@ -10,26 +9,21 @@
// 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_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD

#include "board.h" // Select camera model here (moved since dependencies)
#include "camera_pins.h"

#ifdef CAMERA_MODEL_AI_THINKER
#ifndef CONFIG_LED_ILLUMINATOR_ENABLED
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
#endif
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#endif

#if defined(CONFIG_LED_ILLUMINATOR_ENABLED)
void ledc_setup();
#endif

// ===========================
// Enter your WiFi credentials
// ===========================
Expand All @@ -43,6 +37,10 @@ void setup() {
Serial.setDebugOutput(true);
Serial.println();

#ifdef CAMERA_MODEL_AI_THINKER
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
#endif

camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
Expand Down Expand Up @@ -139,6 +137,10 @@ void setup() {
Serial.print("Camera Ready! Use 'http://");
Serial.print(WiFi.localIP());
Serial.println("' to connect");

#if defined(CONFIG_LED_ILLUMINATOR_ENABLED)
ledc_setup();
#endif
}

void loop() {
Expand Down
22 changes: 22 additions & 0 deletions libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@
#include "img_converters.h"
#include "fb_gfx.h"
#include "driver/ledc.h"

#include "board.h"

#if defined(CAMERA_MODEL_AI_THINKER)
#ifndef CONFIG_LED_ILLUMINATOR_ENABLED
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
#endif
#define CONFIG_LED_MAX_INTENSITY 255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_LED_MAX_INTENSITY - defined but not used anywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_LED_MAX_INTENSITY - defined but not used anywhere.

It used for UI led intensity limit

#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
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;
    }
    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);
    ESP_LOGI(TAG, "Set LED intensity to %d", duty);
}
#endif

#define CONFIG_LED_LEDC_CHANNEL LEDC_CHANNEL_0
#endif

#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
#include "esp32-hal-ledc.h"
#endif

#include "sdkconfig.h"
#include "camera_index.h"

Expand Down Expand Up @@ -279,6 +294,13 @@ static int run_face_recognition(fb_data_t *fb, std::list<dl::detect::result_t> *
#endif

#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
void ledc_setup()
{
// PWM
ledcSetup(LEDC_CHANNEL_0, 4000, LEDC_TIMER_8_BIT);
ledcAttachPin(GPIO_NUM_4, LEDC_CHANNEL_0); // GPIO_NUM_4 = 4
}

void enable_led(bool en)
{ // Turn LED On or Off
int duty = en ? led_duty : 0;
Expand Down
17 changes: 17 additions & 0 deletions libraries/ESP32/examples/Camera/CameraWebServer/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ===================
// 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_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD