Skip to content

Commit 152eec7

Browse files
authored
Framebuffer fix (easytarget#199)
* Slightly longer flash delay, easytarget#188 * Framebuffer delayed frames * Fix Travis, again * show XCLK in dump output * comment on slow XCLK for slow clones * pump up the wifi watchdog default * latest IDE and esp core
1 parent d19dd25 commit 152eec7

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ branches:
1515
before_script:
1616
- "export DISPLAY=:99.0"
1717
- sleep 3 # give xvfb some time to start
18-
- wget https://downloads.arduino.cc/arduino-1.8.18-linux64.tar.xz
19-
- tar xf arduino-1.8.18-linux64.tar.xz
20-
- mv arduino-1.8.18 $HOME/arduino_ide
18+
- wget https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz
19+
- tar xf arduino-1.8.19-linux64.tar.xz
20+
- mv arduino-1.8.19 $HOME/arduino_ide
2121
- cd $HOME/arduino_ide/hardware
2222
- mkdir esp32
2323
- cd esp32
24-
- wget https://github.com/espressif/arduino-esp32/archive/refs/tags/2.0.1.tar.gz
25-
- tar -xzf 2.0.1.tar.gz
26-
- mv arduino-esp32-2.0.1/ esp32
24+
- wget https://github.com/espressif/arduino-esp32/archive/refs/tags/2.0.2.tar.gz
25+
- tar -xzf 2.0.2.tar.gz
26+
- mv arduino-esp32-2.0.2/ esp32
2727
- cd esp32/tools
2828
- python --version
2929
- python get.py

app_httpd.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern int sketchSpace;
6363
extern String sketchMD5;
6464
extern bool otaEnabled;
6565
extern char otaPassword[];
66+
extern unsigned long xclkFreqHz;
6667

6768
typedef struct {
6869
httpd_req_t *req;
@@ -140,9 +141,10 @@ void serialDump() {
140141
int upSec = sec % 60;
141142
int McuTc = (temprature_sens_read() - 32) / 1.8; // celsius
142143
int McuTf = temprature_sens_read(); // fahrenheit
144+
float xclk = xclkFreqHz/1000000;
143145
Serial.printf("System up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)\r\n", upDays, upHours, upMin, upSec);
144146
Serial.printf("Active streams: %i, Previous streams: %lu, Images captured: %lu\r\n", streamCount, streamsServed, imagesServed);
145-
Serial.printf("Freq: %i MHz\r\n", ESP.getCpuFreqMHz());
147+
Serial.printf("CPU Freq: %i MHz, Xclk Freq: %.1f MHz\r\n", ESP.getCpuFreqMHz(), xclk);
146148
Serial.printf("MCU temperature : %i C, %i F (approximate)\r\n", McuTc, McuTf);
147149
Serial.printf("Heap: %i, free: %i, min free: %i, max block: %i\r\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());
148150
if(psramFound()) {
@@ -172,7 +174,10 @@ static esp_err_t capture_handler(httpd_req_t *req){
172174
esp_err_t res = ESP_OK;
173175

174176
Serial.println("Capture Requested");
175-
if (autoLamp && (lampVal != -1)) setLamp(lampVal);
177+
if (autoLamp && (lampVal != -1)) {
178+
setLamp(lampVal);
179+
delay(75); // coupled with the status led flash this gives ~150ms for lamp to settle.
180+
}
176181
flashLED(75); // little flash of status LED
177182

178183
int64_t fr_start = esp_timer_get_time();
@@ -198,12 +203,16 @@ static esp_err_t capture_handler(httpd_req_t *req){
198203
Serial.println("Capture Error: Non-JPEG image returned by camera module");
199204
}
200205
esp_camera_fb_return(fb);
206+
fb = NULL;
207+
201208
int64_t fr_end = esp_timer_get_time();
202209
if (debugData) {
203210
Serial.printf("JPG: %uB %ums\r\n", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start)/1000));
204211
}
205212
imagesServed++;
206-
if (autoLamp && (lampVal != -1)) setLamp(0);
213+
if (autoLamp && (lampVal != -1)) {
214+
setLamp(0);
215+
}
207216
return res;
208217
}
209218

@@ -557,10 +566,11 @@ static esp_err_t dump_handler(httpd_req_t *req){
557566
int upSec = sec % 60;
558567
int McuTc = (temprature_sens_read() - 32) / 1.8; // celsius
559568
int McuTf = temprature_sens_read(); // fahrenheit
569+
float xclk = xclkFreqHz/1000000;
560570

561571
d+= sprintf(d,"Up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)<br>\n", upDays, upHours, upMin, upSec);
562572
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
563-
d+= sprintf(d,"Freq: %i MHz<br>\n", ESP.getCpuFreqMHz());
573+
d+= sprintf(d,"CPU Freq: %i MHz, Xclk Freq: %.1f MHz<br>\n", ESP.getCpuFreqMHz(), xclk);
564574
d+= sprintf(d,"<span title=\"NOTE: Internal temperature sensor readings can be innacurate on the ESP32-c1 chipset, and may vary significantly between devices!\">");
565575
d+= sprintf(d,"MCU temperature : %i &deg;C, %i &deg;F</span>\n<br>", McuTc, McuTf);
566576
d+= sprintf(d,"Heap: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());

esp32-cam-webserver.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern void serialDump();
9595
#endif
9696

9797
#if !defined(WIFI_WATCHDOG)
98-
#define WIFI_WATCHDOG 8000
98+
#define WIFI_WATCHDOG 15000
9999
#endif
100100

101101
// Number of known networks in stationList[]
@@ -137,7 +137,9 @@ char myVer[] PROGMEM = __DATE__ " @ " __TIME__;
137137
// Originally: config.xclk_freq_hz = 20000000, but this lead to visual artifacts on many modules.
138138
// See https://github.com/espressif/esp32-camera/issues/150#issuecomment-726473652 et al.
139139
#if !defined (XCLK_FREQ_HZ)
140-
#define XCLK_FREQ_HZ 16500000;
140+
unsigned long xclkFreqHz = 16500000;
141+
#else
142+
unsigned long xclkFreqHz = XCLK_FREQ_HZ;
141143
#endif
142144

143145
// initial rotation
@@ -522,13 +524,14 @@ void setup() {
522524
config.pin_sscb_scl = SIOC_GPIO_NUM;
523525
config.pin_pwdn = PWDN_GPIO_NUM;
524526
config.pin_reset = RESET_GPIO_NUM;
525-
config.xclk_freq_hz = XCLK_FREQ_HZ;
527+
config.xclk_freq_hz = xclkFreqHz;
526528
config.pixel_format = PIXFORMAT_JPEG;
529+
config.grab_mode = CAMERA_GRAB_LATEST;
527530
// Pre-allocate large buffers
528531
if(psramFound()){
529532
config.frame_size = FRAMESIZE_UXGA;
530533
config.jpeg_quality = 10;
531-
config.fb_count = 6; // We can be generous since we are not using facedetect anymore, allows for bigger jpeg frame size (data)
534+
config.fb_count = 2;
532535
} else {
533536
config.frame_size = FRAMESIZE_SVGA;
534537
config.jpeg_quality = 12;
@@ -638,6 +641,7 @@ void setup() {
638641
// check for saved preferences and apply them
639642

640643
if (filesystem) {
644+
delay(200); // a short delay to let spi bus settle after camera init
641645
filesystemStart();
642646
loadPrefs(SPIFFS);
643647
} else {

myconfig.sample.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ struct station stationList[] = {{"ssid1", "pass1", true},
9999
/*
100100
* Wifi Watchdog defines how long we spend waiting for a connection before retrying,
101101
* and how often we check to see if we are still connected, milliseconds
102-
* You may wish to increase this if your WiFi is slow at conencting,
102+
* You may wish to increase this if your WiFi is slow at conencting.
103103
*/
104-
// #define WIFI_WATCHDOG 8000
104+
// #define WIFI_WATCHDOG 15000
105105

106106
/*
107107
* Over The Air firmware updates can be disabled by uncommenting the folowing line
@@ -187,3 +187,5 @@ struct station stationList[] = {{"ssid1", "pass1", true},
187187
// Currently defaults to 16.5MHz, but some (non-clone) modules may be able to use the
188188
// original frequency of 20MHz for to allow higher framerates etc.
189189
// #define XCLK_FREQ_HZ 20000000;
190+
// For clone modules that have camera module artifacts and SPIFFS issues; try setting this very low:
191+
// #define XCLK_FREQ_HZ 3000000;

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
src_dir = ./
1313

1414
[env:esp32dev]
15-
platform = espressif32
15+
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
16+
platform_packages = framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.2
1617
board = esp32dev
1718
board_build.partitions = min_spiffs.csv
1819
framework = arduino

0 commit comments

Comments
 (0)