Skip to content

Commit 74bf57f

Browse files
Update camera example for support LED Intensity
1 parent 1a7962e commit 74bf57f

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "esp_camera.h"
22
#include <WiFi.h>
3-
43
//
54
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
65
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
@@ -10,26 +9,21 @@
109
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
1110
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
1211

13-
// ===================
14-
// Select camera model
15-
// ===================
16-
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
17-
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
18-
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
19-
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
20-
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
21-
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
22-
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
23-
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
24-
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
25-
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
26-
// ** Espressif Internal Boards **
27-
//#define CAMERA_MODEL_ESP32_CAM_BOARD
28-
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
29-
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
30-
12+
#include "board.h" // Select camera model here (moved since dependencies)
3113
#include "camera_pins.h"
3214

15+
#ifdef CAMERA_MODEL_AI_THINKER
16+
#ifndef CONFIG_LED_ILLUMINATOR_ENABLED
17+
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
18+
#endif
19+
#include "soc/soc.h"
20+
#include "soc/rtc_cntl_reg.h"
21+
#endif
22+
23+
#if defined(CONFIG_LED_ILLUMINATOR_ENABLED)
24+
void ledc_setup();
25+
#endif
26+
3327
// ===========================
3428
// Enter your WiFi credentials
3529
// ===========================
@@ -43,6 +37,10 @@ void setup() {
4337
Serial.setDebugOutput(true);
4438
Serial.println();
4539

40+
#ifdef CAMERA_MODEL_AI_THINKER
41+
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
42+
#endif
43+
4644
camera_config_t config;
4745
config.ledc_channel = LEDC_CHANNEL_0;
4846
config.ledc_timer = LEDC_TIMER_0;
@@ -139,6 +137,10 @@ void setup() {
139137
Serial.print("Camera Ready! Use 'http://");
140138
Serial.print(WiFi.localIP());
141139
Serial.println("' to connect");
140+
141+
#if defined(CONFIG_LED_ILLUMINATOR_ENABLED)
142+
ledc_setup();
143+
#endif
142144
}
143145

144146
void loop() {

libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
#include "img_converters.h"
1818
#include "fb_gfx.h"
1919
#include "driver/ledc.h"
20+
21+
#include "board.h"
22+
23+
#if defined(CAMERA_MODEL_AI_THINKER)
24+
#ifndef CONFIG_LED_ILLUMINATOR_ENABLED
25+
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
26+
#endif
27+
#define CONFIG_LED_MAX_INTENSITY 255
28+
#define CONFIG_LED_LEDC_CHANNEL LEDC_CHANNEL_0
29+
#endif
30+
31+
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
32+
#include "esp32-hal-ledc.h"
33+
#endif
34+
2035
#include "sdkconfig.h"
2136
#include "camera_index.h"
2237

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

281296
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
297+
void ledc_setup()
298+
{
299+
// PWM
300+
ledcSetup(LEDC_CHANNEL_0, 4000, LEDC_TIMER_8_BIT);
301+
ledcAttachPin(GPIO_NUM_4, LEDC_CHANNEL_0); // GPIO_NUM_4 = 4
302+
}
303+
282304
void enable_led(bool en)
283305
{ // Turn LED On or Off
284306
int duty = en ? led_duty : 0;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ===================
2+
// Select camera model
3+
// ===================
4+
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
5+
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
6+
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
7+
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
8+
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
9+
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
10+
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
11+
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
12+
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
13+
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
14+
// ** Espressif Internal Boards **
15+
//#define CAMERA_MODEL_ESP32_CAM_BOARD
16+
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
17+
//#define CAMERA_MODEL_ESP32S3_CAM_LCD

0 commit comments

Comments
 (0)