I am trying to set M5paper to deep sleep and wake up when I press down buttom (GPIO39 to LOW). It is working with arduino:
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_WAKE 25 /* Time ESP32 will wake up (in seconds) */
#include <M5EPD.h>
RTC_DATA_ATTR uint bootCount = 0;
gpio_num_t gpio_num = GPIO_NUM_39;
int count_i = 0;
/*
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(115200);
delay(1000); //Take some time to open up the Serial Monitor
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
print_wakeup_reason();
esp_sleep_enable_timer_wakeup(TIME_TO_WAKE * uS_TO_S_FACTOR);
gpio_pullup_dis(gpio_num);
gpio_pulldown_en(gpio_num);
gpio_hold_en(GPIO_NUM_2); //M5EPD_MAIN_PWR_PIN
gpio_deep_sleep_hold_en();
esp_sleep_enable_ext0_wakeup(gpio_num,LOW); //1 = High, 0 = Low
}
void loop(){
while(count_i < 3){
delay(1000);
Serial.println(count_i);
count_i++;
}
Serial.println("Going to sleep now");
esp_deep_sleep_start();
}
May I ask if it is possible to do the similar thing from mpy, please? Thank you very much
I am trying to set M5paper to deep sleep and wake up when I press down buttom (GPIO39 to LOW). It is working with arduino:
May I ask if it is possible to do the similar thing from mpy, please? Thank you very much