Hallo an alle,
vorsicht bin Anfänger und stelle blöde Fragen!!!!
Genau gesagt geht es um ESp32 und deep sleep.
Grundsätzlich wollte ich fragen ob es mit einem ESP32 überhaupt möglich ist nach einem deep sleep den loop zu nutzen
Was ich bis jetzt so im Internet gelesen habe funktioniert das anscheinend nicht?
Jemand nähere Infos dazu?
Zum Verständnis, habe auf der Uni ein Projekt wo ich ein paar Werte (Temperatur, Tön, etc) 2 oder 3 mal am Tag für 5min messen soll und dann auf einer SD zwischenspeichern und dann über SIM an eine Cloud senden.
Also die Daten einzulesen ist kein Problem, auch das speichern auf der SD Karte ist easy.
Jedoch komme ich mit dem sleep modus vom ESP32 nicht zurecht.
Ich habe auch eine externe RTC DS3231 um Datum und Uhrzeit zu wissen und dann die Datein auf der SD zu benennen, etc...
Mit der DS3231 wollte ich einen das aufwachen aus dem deep sleep bewirken.
Da scheitere ich aber.
Wie gesagt die Bsp welche es im Internet gibt, sagen alle, das der loop nicht ausgeführt werden kann.
Vlt wäre jemand so nett mir zu helfen?
Danke und schöne Grüße
Hab das Bsp gefunden wo der ESP in deep sleep versetzt wird und versucht auf den DS3231 umzubauen, da dieser ja SQW nur low setzten kann, daher eben die abfrage für wacke up ob die beiden Pins 33 und 27 auf low sind und dann einfach das blinken der Led welches als testfunktion im loop
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
RTC_DATA_ATTR int bootCount = 0;
#define LED 2
/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
void setup(){
Serial.begin(9600);
delay(1000); //Take some time to open up the Serial Monitor
pinMode(LED, OUTPUT);
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
/*
First we configure the wake up source
We set our ESP32 to wake up for an external trigger.
There are two types for ESP32, ext0 and ext1 .
ext0 uses RTC_IO to wakeup thus requires RTC peripherals
to be on while ext1 uses RTC Controller so doesnt need
peripherals to be powered on.
Note that using internal pullups/pulldowns also requires
RTC peripherals to be turned on.
*/
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,0); //1 = High, 0 = Low //Pin 33
esp_sleep_enable_ext1_wakeup(0x8000000,ESP_EXT1_WAKEUP_ALL_LOW); //Pin 27
//If you were to use ext1, you would use it like
//esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
//Go to sleep now
Serial.println("Going to sleep now");
delay(1000);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop(){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
//delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
//delay(1000); // wait for a second
//delay(1000); //Take some time to open up the Serial Monitor
}
Und der code den ich gefunden habe um den Interupt vom DS3231 zu triggern:
/* Example implementation of an alarm using DS3231
*
* VCC and GND of RTC should be connected to some power source
* SDA, SCL of RTC should be connected to SDA, SCL of arduino
* SQW should be connected to CLOCK_INTERRUPT_PIN
* CLOCK_INTERRUPT_PIN needs to work with interrupts
*/
#include <RTClib.h>
// #include <Wire.h>
RTC_DS3231 rtc;
// the pin that is connected to SQW
#define CLOCK_INTERRUPT_PIN 2
void setup() {
Serial.begin(9600);
// initializing the rtc
if(!rtc.begin()) {
Serial.println("Couldn't find RTC!");
Serial.flush();
abort();
}
// 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();
// Making it so, that the alarm will trigger an interrupt
//pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm, FALLING);
// 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 10 seconds in the future
if(!rtc.setAlarm1(
rtc.now() + TimeSpan(10),
DS3231_A1_Second // this mode triggers the alarm when the seconds match. See Doxygen for other options
)) {
Serial.println("Error, alarm wasn't set!");
}else {
Serial.println("Alarm will happen in 10 seconds!");
}
}
void loop() {
// print current time
char date[10] = "hh:mm:ss";
rtc.now().toString(date);
Serial.println(date);
// resetting SQW and alarm 1 flag
// using setAlarm1, the next alarm could now be configurated
if(rtc.alarmFired(1)) {
rtc.clearAlarm(1);
Serial.println("Alarm cleared");
}
delay(2000);
}
void onAlarm() {
Serial.println("Alarm occured!");
}
Vlt wäre jemand so nett mir zu helfen ob und wie es möglich ist das zu kombinieren, sodass die LED 1min blinkt und dann 1 min im deep sleep ist.
Bin für jeden Tipp dankbar.
Nochmals schone Grüße