Merge pull request #53 from rzeldent/feature/psram

Added setting for PSRAM and Buffers
This commit is contained in:
rzeldent
2023-03-25 21:35:42 +01:00
committed by GitHub
5 changed files with 103 additions and 45 deletions

View File

@@ -30,6 +30,7 @@ This software provides a **configuration web server**, that can be used to:
- Select the image size,
- Select the frame rate,
- Select the JPEG quality
- Enable the use of the PSRAM
- Configure the camera options:
- Brightness
- Contrast
@@ -244,13 +245,42 @@ Make sure the power is 5 volts and stable, although the ESP32 is a 3.3V module,
If not stable, it has been reported that restarts occur when starting up (probably when power is required for WiFi).
The software disables the brown out protection so there is some margin in the voltage.
### PSRAM
### PSRAM / Buffers / JPeg quality
Some esp32cam modules have additional ram on the board. This allows to use this ram as frame buffer.
Detecting and using this special RAM is handled automatically.
The availability of PSRAM can be seen in the HTML status overview.
### Camera modules
Not all the boards areq equipped with PSRAM:
| Board | PSRAM |
|--- |--- |
| ESP32CAM | Yes |
| ESP32CAM (USB-C) | No |
| AI THINKER | Yes |
| TTGO T-CAM | No |
| M5 STACK| | No |
| WROVER KIT | Yes |
Depending on the image resolution, framerate and quality, the PSRAM must be enabled and/or the number of frame buffers increased to keep up with the data generated by the sensor.
There are (a lot of?) boards around with faulty PSRAM. If the camera fails to initialize, this might be a reason.
In this case disable the use of PSRAM in the configuration and do not use camera modes that require PSRAM,
For the setting JPeg quality, a lower number means higher quality.
Be aware that a very high quality (low number) can cause the ESP32 cam to crash or return no image.
The default settings are:
- No PSRAM
- SVGA (800x600)
- 1 frame buffer
- JPeg quality 12
- With PSRAM
- UXGA (1600x1200)
- 2 frame buffers
- jpeg quality 10
### Camera module
Be careful when connecting the camera module.
Make sure it is connected the right way around (Camera pointing away from the board) and the ribbon cable inserted to the end before locking it.

View File

@@ -26,6 +26,10 @@
<div class="card bg-light mb-3">
<h5 class="card-header">ESP32</h5>
<div class="card-body">
<div class="row">
<div class="col-4">SDK Version:</div>
<div class="col-8">{{SDKVersion}}</div>
</div>
<div class="row">
<div class="col-4">CPU model:</div>
<div class="col-8">{{ChipModel}} rev. {{ChipRevision}}</div>
@@ -125,12 +129,12 @@
</div>
{{#NetworkState.ApMode}}
<div class="mt-4 alert alert-warning" role="alert">
<p>Not connected to an access point. Consider configuring the access point.</p>
<h4 class="text-center">Not connected to an access point.<br>Consider configuring the access point.</h4>
</div>
{{/NetworkState.ApMode}}
{{#NetworkState.OnLine}}
<div class="mt-4 alert alert-success" role="alert">
<p>Connected to the access point</p>
<h4 class="text-center">Connected to the access point</h4>
</div>
{{/NetworkState.OnLine}}
</div>
@@ -148,18 +152,18 @@
<div class="col-4">Frame size:</div>
<div class="col-8">{{FrameSize}}</div>
</div>
<div class="row">
<div class="col-4">Frame buffer location:</div>
<div class="col-8">{{FrameBufferLocation}}</div>
</div>
<div class="row">
<div class="col-4">Frame buffers:</div>
<div class="col-8">{{FrameBuffers}}</div>
</div>
<div class="row">
<div class="col-4">JPEG quality:</div>
<div class="col-8">{{JpegQuality}} [1-100]</div>
</div>
<div class="row">
<div class="col-4">Enable PSRAM:</div>
<div class="col-8">{{#EnablePSRAM}}Enabled{{/EnablePSRAM}}{{^EnablePSRAM}}Disabled{{/EnablePSRAM}}</div>
</div>
<div class="row">
<div class="col-4">Number of frame buffers:</div>
<div class="col-8">{{FrameBuffers}}</div>
</div>
<div class="row">
<div class="col-4">Brightness:</div>
<div class="col-8">{{Brightness}} [-2,2]</div>
@@ -178,11 +182,11 @@
</div>
<div class="row">
<div class="col-4">White balance:</div>
<div class="col-8">{{WhiteBal}}</div>
<div class="col-8">{{#WhiteBal}}Auto{{/WhiteBal}}{{^WhiteBal}}Manual{{/WhiteBal}}</div>
</div>
<div class="row">
<div class="col-4">AWB gain:</div>
<div class="col-8">{{AwbGain}}</div>
<div class="col-8">{{#AwbGain}}Auto{{/AwbGain}}{{^AwbGain}}Manual{{/AwbGain}}</div>
</div>
<div class="row">
<div class="col-4">WB mode:</div>
@@ -190,11 +194,12 @@
</div>
<div class="row">
<div class="col-4">Exposure control:</div>
<div class="col-8">{{ExposureCtrl}}</div>
<div class="col-8">
{{#ExposureCtrl}}Auto{{/ExposureCtrl}}{{^ExposureCtrl}}Manual{{/ExposureCtrl}}</div>
</div>
<div class="row">
<div class="col-4">Auto exposure control (dsp):</div>
<div class="col-8">{{Aec2}}</div>
<div class="col-8">{{#Aec2}}Enabled{{/Aec2}}{{^Aec2}}Disabled{{/Aec2}}</div>
</div>
<div class="row">
<div class="col-4">Auto Exposure level:</div>
@@ -206,7 +211,7 @@
</div>
<div class="row">
<div class="col-4">Gain control:</div>
<div class="col-8">{{GainCtrl}}</div>
<div class="col-8">{{#GainCtrl}}Auto{{/GainCtrl}}{{^GainCtrl}}Manual{{/GainCtrl}}</div>
</div>
<div class="row">
<div class="col-4">AGC gain:</div>
@@ -218,48 +223,47 @@
</div>
<div class="row">
<div class="col-4">Black pixel correct:</div>
<div class="col-8">{{Bpc}}</div>
<div class="col-8">{{#Bpc}}Auto{{/Bpc}}{{^Bpc}}Manual{{/Bpc}}</div>
</div>
<div class="row">
<div class="col-4">White pixel correct:</div>
<div class="col-8">{{Wpc}}</div>
<div class="col-8">{{#Wpc}}Auto{{/Wpc}}{{^Wpc}}Manual{{/Wpc}}</div>
</div>
<div class="row">
<div class="col-4">Gamma correct:</div>
<div class="col-8">{{RawGma}}</div>
<div class="col-8">{{#RawGma}}Enabled{{/RawGma}}{{^RawGma}}Disabled{{/RawGma}}</div>
</div>
<div class="row">
<div class="col-4">Lens correction:</div>
<div class="col-8">{{Lenc}}</div>
<div class="col-8">{{#Lenc}}Enabled{{/Lenc}}{{^Lenc}}Disabled{{/Lenc}}</div>
</div>
<div class="row">
<div class="col-4">Horizontal mirror:</div>
<div class="col-8">{{HMirror}}</div>
<div class="col-8">{{#HMirror}}Mirrored{{/HMirror}}{{^HMirror}}Normal{{/HMirror}}</div>
</div>
<div class="row">
<div class="col-4">Vertical flip:</div>
<div class="col-8">{{VFlip}}</div>
<div class="col-8">{{#VFlip}}Flipped{{/VFlip}}{{^VFlip}}Normal{{/VFlip}}</div>
</div>
<div class="row">
<div class="col-4">Downsize enable:</div>
<div class="col-8">{{Dcw}}</div>
<div class="col-8">{{#Dcw}}Enabled{{/Dcw}}{{^Dcw}}Disabled{{/Dcw}}</div>
</div>
<div class="row">
<div class="col-4">Color bar:</div>
<div class="col-8">{{ColorBar}}</div>
<div class="col-8">{{#ColorBar}}Enabled{{/ColorBar}}{{^ColorBar}}Camera{{/ColorBar}}</div>
</div>
{{#CameraInitialized}}
<div class="mt-4 alert alert-success" role="alert">
<p>Camera was initialized successfully!</p>
<h4 class="text-center">Camera was initialized successfully!</h4>
</div>
{{/CameraInitialized}}
{{^CameraInitialized}}
<div class="mt-4 alert alert-danger" role="alert">
<p>Failed to initialize the camera!</p>
<p>Result: {{CameraInitResultText}}</p>
<h4 class="text-center">Failed to initialize the camera!</h4>
<p>Result: {{CameraInitResult}} ({{CameraInitResultText}})</p>
<p>Please check hardware or correct the camera settings and restart.</p>
<button type="button" class="btn btn-danger"
onclick="location.href='restart'">Restart</button>
<button type="button" class="btn btn-danger" onclick="location.href='restart'">Restart</button>
</div>
{{/CameraInitialized}}
</div>
@@ -287,7 +291,7 @@
<span>
The intensity of the flash led (0-255) can be controlled using:
<a href="http://{{IpV4}}/flash?v=0">http://{{IpV4}}/flash?v=value</a>.
Authentication is required and if no value is present, the configuration value is used.
Authentication is required.
</span>
</div>
<div class="row">

File diff suppressed because one or more lines are too long

View File

@@ -5,15 +5,17 @@
#define WIFI_SSID "ESP32CAM-RTSP"
#define WIFI_PASSWORD nullptr
#define CONFIG_VERSION "1.4"
#define CONFIG_VERSION "1.5"
#define OTA_PASSWORD "ESP32CAM-RTSP"
#define RTSP_PORT 554
#define DEFAULT_CAMERA_CONFIG "AI THINKER"
#define DEFAULT_ENABLE_PSRAM psramFound()
#define DEFAULT_BUFFERS (psramFound() ? 2 : 1)
#define DEFAULT_FRAME_DURATION 100
#define DEFAULT_FRAME_SIZE (psramFound() ? "UXGA (1600x1200)" : "VGA (640x480)")
#define DEFAULT_FRAME_SIZE (psramFound() ? "UXGA (1600x1200)" : "SVGA (800x600)")
#define DEFAULT_JPEG_QUALITY (psramFound() ? 10 : 12)
#define DEFAULT_BRIGHTNESS 0

View File

@@ -1,5 +1,6 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <esp_wifi.h>
#include <soc/rtc_cntl_reg.h>
#include <IotWebConf.h>
#include <IotWebConfTParameter.h>
@@ -25,6 +26,8 @@ auto param_group_camera = iotwebconf::ParameterGroup("camera", "Camera settings"
auto param_frame_duration = iotwebconf::Builder<iotwebconf::UIntTParameter<unsigned long>>("fd").label("Frame duration (ms)").defaultValue(DEFAULT_FRAME_DURATION).min(10).build();
auto param_frame_size = iotwebconf::Builder<iotwebconf::SelectTParameter<sizeof(frame_sizes[0])>>("fs").label("Frame size").optionValues((const char *)&frame_sizes).optionNames((const char *)&frame_sizes).optionCount(sizeof(frame_sizes) / sizeof(frame_sizes[0])).nameLength(sizeof(frame_sizes[0])).defaultValue(DEFAULT_FRAME_SIZE).build();
auto param_jpg_quality = iotwebconf::Builder<iotwebconf::UIntTParameter<byte>>("q").label("JPG quality").defaultValue(DEFAULT_JPEG_QUALITY).min(1).max(100).build();
auto param_enable_psram = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("eps").label("Enable PSRAM if available").defaultValue(DEFAULT_ENABLE_PSRAM).build();
auto param_frame_buffers = iotwebconf::Builder<iotwebconf::IntTParameter<int>>("fb").label("Buffers").defaultValue(DEFAULT_BUFFERS).min(1).max(4).build();
auto param_brightness = iotwebconf::Builder<iotwebconf::IntTParameter<int>>("b").label("Brightness").defaultValue(DEFAULT_BRIGHTNESS).min(-2).max(2).build();
auto param_contrast = iotwebconf::Builder<iotwebconf::IntTParameter<int>>("c").label("Contrast").defaultValue(DEFAULT_CONTRAST).min(-2).max(2).build();
auto param_saturation = iotwebconf::Builder<iotwebconf::IntTParameter<int>>("s").label("Saturation").defaultValue(DEFAULT_SATURATION).min(-2).max(2).build();
@@ -98,6 +101,7 @@ void handle_root()
{"AppTitle", APP_TITLE},
{"AppVersion", APP_VERSION},
{"ThingName", iotWebConf.getThingName()},
{"SDKVersion", ESP.getSdkVersion()},
{"ChipModel", ESP.getChipModel()},
{"ChipRevision", String(ESP.getChipRevision())},
{"CpuFreqMHz", String(ESP.getCpuFreqMHz())},
@@ -109,7 +113,7 @@ void handle_root()
{"Uptime", String(format_duration(millis() / 1000))},
{"FreeHeap", format_memory(ESP.getFreeHeap())},
{"MaxAllocHeap", format_memory(ESP.getMaxAllocHeap())},
{"NumRTSPSessions", camera_server != nullptr ? String(camera_server->num_connected()) : "N/A"},
{"NumRTSPSessions", camera_server != nullptr ? String(camera_server->num_connected()) : "RTSP server disabled"},
// Network
{"HostName", hostname},
{"MacAddress", WiFi.macAddress()},
@@ -125,10 +129,11 @@ void handle_root()
{"FrameSize", String(param_frame_size.value())},
{"FrameDuration", String(param_frame_duration.value())},
{"FrameFrequency", String(1000.0 / param_frame_duration.value(), 1)},
{"FrameBufferLocation", psramFound() ? "PSRAM" : "DRAM)"},
{"FrameBuffers", String(psramFound() ? 2 : 1)},
{"JpegQuality", String(param_jpg_quality.value())},
{"EnablePSRAM", String(param_enable_psram.value())},
{"FrameBuffers", String(param_frame_buffers.value())},
{"CameraInitialized", String(camera_init_result == ESP_OK)},
{"CameraInitResult", String(camera_init_result)},
{"CameraInitResultText", esp_err_to_name(camera_init_result)},
// Settings
{"Brightness", String(param_brightness.value())},
@@ -194,7 +199,7 @@ void handle_snapshot()
return;
}
// Remove old images stored in the framebuffer
// Remove old images stored in the frame buffer
auto frame_buffers = psramFound() ? 2 : 1;
while (frame_buffers--)
cam.run();
@@ -243,24 +248,33 @@ esp_err_t initialize_camera()
{
log_v("initialize_camera");
log_i("Camera config: %s", param_board.value());
auto camera_config = lookup_camera_config(param_board.value());
auto camera_config_template = lookup_camera_config(param_board.value());
// Copy the settings
camera_config_t camera_config;
memset(&camera_config, 0, sizeof(camera_config_t));
memcpy(&camera_config, &camera_config_template, sizeof(camera_config_t));
log_i("Frame size: %s", param_frame_size.value());
auto frame_size = lookup_frame_size(param_frame_size.value());
log_i("JPEG quality: %d", param_jpg_quality.value());
log_i("Frame duration: %d ms", param_frame_duration.value());
camera_config.frame_size = frame_size;
camera_config.jpeg_quality = param_jpg_quality.value();
if (psramFound())
camera_config.grab_mode = CAMERA_GRAB_LATEST;
log_i("Enable PSRAM: %d", param_enable_psram.value());
log_i("Buffers: %d", param_frame_buffers.value());
camera_config.fb_count = param_frame_buffers.value();
if (param_enable_psram.value() && psramFound())
{
camera_config.fb_count = 2;
camera_config.fb_location = CAMERA_FB_IN_PSRAM;
log_i("PSRAM enabled!");
}
else
{
camera_config.fb_count = 1;
camera_config.fb_location = CAMERA_FB_IN_DRAM;
log_i("PSRAM disabled");
}
return cam.init(camera_config);
}
@@ -314,9 +328,11 @@ void on_connected()
analogWrite(LED_FLASH, param_led_intensity.value());
// Start (OTA) Over The Air programming when connected
ArduinoOTA.begin();
// Start the RTSP Server if initializef
// Start the RTSP Server if initialized
if (camera_init_result == ESP_OK)
start_rtsp_server();
else
log_e("Not starting RTSP server: camera not initialized");
}
void on_config_saved()
@@ -349,14 +365,20 @@ void setup()
log_i("CPU Freq: %d Mhz", getCpuFrequencyMhz());
log_i("Free heap: %d bytes", ESP.getFreeHeap());
log_i("SDK version: %s", ESP.getSdkVersion());
log_i("Starting " APP_TITLE "...");
if (psramFound())
psramInit();
param_group_board.addItem(&param_board);
iotWebConf.addParameterGroup(&param_group_board);
param_group_camera.addItem(&param_frame_duration);
param_group_camera.addItem(&param_frame_size);
param_group_camera.addItem(&param_jpg_quality);
param_group_camera.addItem(&param_enable_psram);
param_group_camera.addItem(&param_frame_buffers);
param_group_camera.addItem(&param_brightness);
param_group_camera.addItem(&param_contrast);
param_group_camera.addItem(&param_saturation);