For a project where I'm using the ESP32-CAM with a battery (18650 battery) I need the power consumption as low as it can. The sleepmode doesn't do it for me. It still consumes way to much than needed. I found an article where they use an RTC with a mosfet to power on and off a ESP32. I got it working that the ESP32-CAM turns on every minute.
The problem I have is that is goes off way to fast. I need the ESP32-CAM to be on until a photo is send to the server.
This is my code example I use for the RTC with mosfet.
#include <RTClib.h>
#include <Wire.h>
#include <Arduino.h>
// #include "soc/soc.h"
// #include "soc/rtc_cntl_reg.h"
#define I2C_SDA 14
#define I2C_SDL 15
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SDL);
// initializing the rtc
if (!rtc.begin()) {
Serial.println("Couldn't find RTC!");
Serial.flush();
while (1) delay(10);
}
if (rtc.lostPower()) {
// this will adjust to the date and time at compilation
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
//we don't need the 32K Pin, so disable it
rtc.disable32K();
// set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)
// if not done, this easily leads to problems, as both register aren't reset on reboot/recompile
rtc.clearAlarm(1);
rtc.clearAlarm(2);
// stop oscillating signals at SQW Pin
// otherwise setAlarm1 will fail
rtc.writeSqwPinMode(DS3231_OFF);
// turn off alarm 2 (in case it isn't off already)
// again, this isn't done at reboot, so a previously set alarm could easily go overlooked
rtc.disableAlarm(2);
// schedule an alarm
if (!rtc.setAlarm1(
DateTime(0,0,0,0,0,0),
DS3231_A1_Second // this mode triggers the alarm when the seconds match. See Doxygen for other options
)) {
Serial.println("Error, alarm wasn't set!");
}
}
void loop() {
// print current time
char date[10] = "hh:mm:ss";
rtc.now().toString(date);
Serial.println(date);
// using setAlarm1, the next alarm could now be configurated
if (rtc.alarmFired(1)) {
Serial.println("Do something");
rtc.clearAlarm(1);
Serial.println("Alarm cleared");
}
Serial.println(" ");
delay(1000);
}
How can I make it so that the RTC stays on for a longer time period when the alarm is triggered?
First you should look at the ESP32CAM Schematic, just because the board has pins numbered it does not mean they are free to use, as in not connected to other stuff.
The RTC and the SD card could interfere with each other, the SD card might lock up for instance. It might work if the RTC is setup and used before the SD card is set up and used, or vice versa, but dont expect to be able to use both at the same time.
Ultimatly you can, for reliability, put the I2C on the UOT and UOR serial pins, since for an installed application you dont normally need Serial output.
From what I can see is that GPIO 16 is connected to the PSRAM CS pin. I don't know if that would be a problem. The only free pins are GPIO 1 and GPIO 3.
In the loop I have a if statement for the alarm. Even when I clear the alarm after the picture take function it still turns off before it can even connect to the internet, so that doesn't work. Something makes the alarm go off immediately.