【发布时间】:2020-07-08 09:58:05
【问题描述】:
所以一些背景知识 - 我有一个带有 PIR 传感器的 esp32 cam。 esp 处于深度睡眠状态,然后被 PIR 传感器 (GPIO 13) 唤醒,esp 拍摄图像。然后我想要它做的是监视另外 15 秒的运动。如果有运动,它应该再拍一张照片等等。 15 秒后,esp 应该将照片发送到服务器(还没有到达这部分)。
问题是当唤醒后检测到运动时,相机无法初始化并且esp会自动重启。
代码是
#include "esp_camera.h"
#include "Arduino.h"
#include "FS.h" // SD Card ESP32
#include "SD_MMC.h" // SD Card ESP32
#include "soc/soc.h" // Disable brownour problems
#include "soc/rtc_cntl_reg.h" // Disable brownour problems
#include "driver/rtc_io.h"
#include <EEPROM.h> // read and write from flash memory
#include "DHT.h" //Vir temperatuur sensor
#include <WiFi.h>"
#define EEPROM_SIZE 1
RTC_DATA_ATTR int bootCount = 0;
// Pin definition for CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
int pictureNumber = 0;
void initSDCard( void ) {
if( !SD_MMC.begin() ) { // fast 4bit mode
if( !SD_MMC.begin( "/sdcard", true ) ) { // slow 1bit mode
Serial.println( "SD card init failed" );
return;
}
}
}
void captureImage(void){
Serial.setDebugOutput(true);
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
pinMode(4, INPUT);
digitalWrite(4, LOW);
rtc_gpio_hold_dis(GPIO_NUM_4);
if(psramFound()){
config.frame_size = FRAMESIZE_VGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
// Init Camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
Serial.println("Starting SD Card");
delay(500);
initSDCard(); //initialise SD card
camera_fb_t * fb = NULL;
// Take Picture with Camera
fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
return;
}
// initialize EEPROM with predefined size
EEPROM.begin(EEPROM_SIZE);
pictureNumber = EEPROM.read(0) + 1; //keeps count of picture number
// Path where new picture will be saved in SD Card
String path = "/picture" + String(pictureNumber) +".jpg";
fs::FS &fs = SD_MMC;
Serial.printf("Picture file name: %s\n", path.c_str());
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.printf("Saved file to path: %s\n", path.c_str());
EEPROM.write(0, pictureNumber);
EEPROM.commit();
}
file.close();
esp_camera_fb_return(fb);
delay(1000);
// Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4
pinMode(4, OUTPUT);
digitalWrite(4, LOW);
rtc_gpio_hold_en(GPIO_NUM_4);
}
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
captureImage();
int start = millis();
int endtime = start;
while(endtime - start <= 15000){
int motion = digitalRead(13);
if(motion == HIGH){
Serial.println("Detected");
captureImage();
}
else{
Serial.println("No motion Detected");
endtime = millis();
}
}
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, HIGH); //PIR sensor will trigger wake up from deep sleep.
Serial.print("going to sleep");
esp_deep_sleep_start();
}
void loop() {}
所以当检测到运动时,我会收到以下错误消息:
未检测到运动
未检测到运动
检测到
[E][camera.c:1249] esp_camera_init():相机探测失败,错误 0x103
E (5592) i2c:i2c 驱动程序安装 erroGuru Meditation 错误:Core 1 出现恐慌 (IntegerDivideByZero)。异常未处理。
核心 1 寄存器转储:
PC : 0x40089b04 PS : 0x00060031 A0 : 0x80089fb1 A1 : 0x3ffbe770
A2:0x3ffbe7af A3:0x00000000 A4:0x00060023 A5:0x3ffb8058
A6:0x00000000 A7:0x00000000 A8:0x3ffb843c A9:0x00000001
A10:0x00000000 A11:0x3ffb0060 A12:0x00000020 A13:0x80000020
A14:0x00000008 A15:0x00000001 SAR:0x0000001c EXCCAUSE:0x00000006
EXCVADDR:0x00000000 LBEG:0x400014fd 借出:0x4000150d LCOUNT:0xffffffffe
Core 1 在 ISR 上下文中运行:
EPC1:0x40089b04 EPC2:0x00000000 EPC3:0x00000000 EPC4:0x4008b8f7
回溯:0x40089b04:0x3ffbe770 0x40089fae:0x3ffbe7a0 0x4008754d:0x3ffbe7d0 0x400e27d9:0x3ffb1910 0x400e34ec:0x3ffb1930 0x400e39e7:0x3ffb1950 0x4000bd83:0x3ffb1970 0x4000117d:0x3ffb1990 0x400592fe:0x3ffb19b0 0x4005937a:0x3ffb19d0 0x40058bbf:0x3ffb19f0 0x400e9761:0x3ffb1a20 0x400eef4a:0x3ffb1a50 0x400ef08d:0x3ffb1d60 0x40087152:0x3ffb1d90 0x400FFB55:0x3FFB1DE0 0x400F93BB:0x3FFB1E10 0x400F898A:0x3FFB1E50 0x400F9140:0x3FFB1E90 0x400D1CDE:0x3FFB1EC0 0x400D1F3F:0x3FFB1F80 0x400D3AE7:0x3FFB1FB0 0x4008EB75:0x3FFB1FD0 P>
正在重新启动... 等 2016 年 6 月 8 日 00:22:57
我对编程还很陌生,因此对于如何修复代码或实现目标的任何建议将不胜感激。
【问题讨论】:
-
为什么要禁用掉电检测器?
-
说实话 - 我不太确定。我从一个教程中得到它来设置相机。还在调查那个。但我是用我的电脑 USB 供电的,所以电源应该不是问题,但是当我用电池运行时,我会再次启用它。
-
我会尝试评论该行。通常 PC USB 端口供电不足。您可能会发现自己正在断电,这意味着您需要更强大的电源。