m5stack / M5Dial

51 stars 10 forks source link

Cannot wakeup from deep sleep with WAKE button #11

Open MitchBradley opened 6 months ago

MitchBradley commented 6 months ago

The documentation and schematics say that GPIO 42 - the dial switch - is for WAKE. When I put the ESP32-S3 into deep sleep mode, I cannot get it to wake up by pressing the dial switch.

The Espressif documents say that only RTC GPIOs can be used for wakeup from deep sleep. According to the ESP32-S3 datasheet at https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf , only GPIOS 0-21 are RTC GPIOs.

Is there any way to wake from deep sleep with a button press on the M5 Dial?

felmue commented 6 months ago

Hello @MitchBradley

the dial switch cannot be used to wakeup ESP32 from light or deep sleep, for the reason you already mentioned above - GPIO42 is not an RTC GPIO.

Edit: I just found out that the dial switch can be used to wakeup ESP32 from light sleep using GPIO Wakeup. See here.

What the dial switch can do is wake the system from a full shutdown state.

Thanks Felix

MitchBradley commented 6 months ago

What do you mean by full shutdown? How does one enter "full shutdown" ?

felmue commented 6 months ago

Hello @MitchBradley

please have a look at the wakeup example here.

Below line (commented out in the example) does a full shutdown.

M5Dial.Power.powerOff();

Note: in full shutdown state only the RTC IC (RTC8563) is still powered which can also be used to wake up after some time.

Thanks Felix

jsgagnon2020 commented 5 months ago

Hello, Based on the previous comment and my tests, it is possible to go in "sleep mode" /or/ "shutdown mode" by coding uniquely. (the example does that)

But Is it possible to get out of these two modes uniquely base on the "rotating knob" /or/ "push button" /or/ "touch screen" ?

Meaning: Waking up from sleep or shutdown the M5Dial uniquely with the "rotating knob" /or/ "push button" /or/ "touch screen" ? att.: Uniquely and NOT through a pin state?

Thank, JS

felmue commented 5 months ago

Hello @jsgagnon2020

A: Getting out of shutdown mode is only possible via "push button" (WAKE) or RTC (INT) which are connected to the wake-up circuit. See schematic here. ("rotating knob" and "touch screen" are not connected to the wake-up circuit.)

B: Getting out of sleep mode is only possible via "touch screen" (TP_INT) which uses an RTC GPIO. ("rotating knob" and "push button" cannot be used to wake from deep sleep as they are connected to non RTC GPIOs.)

Edit: "rotating knob" and "push button" can be used to wake up from light sleep using GPIO Wakeup. See here.

You can use the wake-up cause to figure out what has woken up the system. See here.

For A: the wake-up cause should be ESP_SLEEP_WAKEUP_UNDEFINED.

For B: the wake-up cause should be not ESP_SLEEP_WAKEUP_UNDEFINED.

Note: above info is based on reading schematic and documents only - not tested with hardware - so I could be wrong.

Thanks Felix

jsgagnon2020 commented 5 months ago

:) :) most appreciated, when I will have the Arduino code for the M5Dial, I will share it

felmue commented 5 months ago

Hello @jsgagnon2020

I've created a simple example show-casting sleep modes and waking from touch screen or dial button.

Thanks Felix

jsgagnon2020 commented 5 months ago

Mostly appreciated! 😊

Envoyé à partir de Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows


De : felmue @.> Envoyé : Friday, February 9, 2024 7:06:43 AM À : m5stack/M5Dial @.> Cc : jsgagnon2020 @.>; Mention @.> Objet : Re: [m5stack/M5Dial] Cannot wakeup from deep sleep with WAKE button (Issue #11)

Hello @jsgagnon2020https://github.com/jsgagnon2020

I've created a simple example show-casting sleep modes and waking from touch screen or dial button.

Thanks Felix

— Reply to this email directly, view it on GitHubhttps://github.com/m5stack/M5Dial/issues/11#issuecomment-1935812736, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOLSZ7VDAH4Z4GYPIGM6C6LYSYGNHAVCNFSM6AAAAABBUIVYUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZVHAYTENZTGY. You are receiving this because you were mentioned.Message ID: @.***>

jsgagnon2020 commented 5 months ago

After testing,

I found out that only the touchPad work for the deepsleep

Thank to all

Here is my code for the M5Dial

//--------------

include

include "M5Dial.h"

RTC_DATA_ATTR int mode = 0;

define uS_TO_S_FACTOR 1000000

define TIME_TO_SLEEP 5

unsigned long last_interaction = 0;

void setup() { auto cfg = M5.config(); M5Dial.begin(cfg, true, false); M5Dial.Display.setTextColor(GREEN); M5Dial.Display.setTextDatum(middle_center); M5Dial.Display.setTextFont( &fonts::FreeSerifItalic18pt7b); M5Dial.Display.setTextSize( 1); M5Dial.Display.drawString("Sleep tests", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 70); delay(2000);

          esp_sleep_wakeup_cause_t wakeup_reason;         wakeup_reason = esp_sleep_get_wakeup_cause();
          // esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

          if ( mode   == 0)                   {             M5Dial.Display.drawString("Start",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 40); }

          if ( mode   == 1)                   { mode   = 0; M5Dial.Display.drawString("Result",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 40);
                                                switch(wakeup_reason)        {
                                                                               case ESP_SLEEP_WAKEUP_EXT0 :     M5Dial.Display.drawString("Touch"  , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_EXT1 :     M5Dial.Display.drawString("Ext1"   , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_TIMER :    M5Dial.Display.drawString("timer"  , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_TOUCHPAD : M5Dial.Display.drawString("???"    , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_ULP :      M5Dial.Display.drawString("5"      , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               default :                        M5Dial.Display.drawString("button" , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                             }
                                                delay(5000);
                                                M5Dial.Display.clear();
                                              }
        }

void loop() {

          M5Dial.update();
          M5Dial.Display.drawString("Sleep tests",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 70);

          esp_sleep_wakeup_cause_t wakeup_reason;         wakeup_reason = esp_sleep_get_wakeup_cause();

          if ( mode   == 0)                   {             M5Dial.Display.drawString("Start",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 40); }

          if ( mode   == 1)                   { mode   = 0; M5Dial.Display.drawString("Result",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 40);
                                                switch(wakeup_reason)        {
                                                                               case ESP_SLEEP_WAKEUP_EXT0 :     M5Dial.Display.drawString("Touch"  , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_EXT1 :     M5Dial.Display.drawString("Ext1"   , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_TIMER :    M5Dial.Display.drawString("timer"  , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_TOUCHPAD : M5Dial.Display.drawString("???"    , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               case ESP_SLEEP_WAKEUP_ULP :      M5Dial.Display.drawString("5"      , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                               default :                        M5Dial.Display.drawString("button" , M5Dial.Display.width() / 2,  M5Dial.Display.height() / 2 + 30); break;
                                                                             }
                                                delay(5000);
                                                M5Dial.Display.clear();
                                              }

//-------------- 1) To test light sleep initiate by the button and wakeup from the button // if (M5Dial.BtnA.wasPressed()) { mode = 1; // M5Dial.Display.clear(); // M5Dial.Display.drawString("LSleep", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 10); // M5Dial.Display.drawString("Button", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20); // delay(1000); // M5Dial.Display.clear(); // gpio_wakeup_enable(GPIO_NUM_42, GPIO_INTR_LOW_LEVEL); esp_sleep_enable_gpio_wakeup(); esp_light_sleep_start(); // } // //-------------- 2) To test deep sleep initiate by the button and wakeup from the button (DOES NOT WORK) // if (M5Dial.BtnA.wasPressed()) { mode = 1; // M5Dial.Display.clear(); // // M5Dial.Display.drawString("DSleep", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 10); // M5Dial.Display.drawString("Button", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20); // delay(1000); // M5Dial.Display.clear(); // gpio_wakeup_enable(GPIO_NUM_42, GPIO_INTR_LOW_LEVEL); esp_sleep_enable_gpio_wakeup(); esp_deep_sleep_start(); // } // // //-------------- 3) To test sleep (M5Dial function) initiate by the button and wakeup from the timer // if (M5Dial.BtnA.wasPressed()) { mode = 1; // M5Dial.Display.clear(); // // M5Dial.Display.drawString("LSleep_M5", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 10); // M5Dial.Display.drawString("Timer ", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20); // delay(1000); // M5Dial.Display.clear(); // M5Dial.Power.timerSleep(5); // }

//-------------- 4) To test sleep (ESP32 function) initiate by the button and wakeup from the timer // if (M5Dial.BtnA.wasPressed()) { mode = 1; // M5Dial.Display.clear(); // // M5Dial.Display.drawString("LSleep_Hd", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 10); // M5Dial.Display.drawString("Timer ", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20); // delay(1000); // M5Dial.Display.clear(); // esp_light_sleep_start(); // }

//-------------- 5) To test light sleep (ESP32 function) initiate by the button and wakeup from the TouchPad // if (M5Dial.BtnA.wasPressed()) { mode = 1; // M5Dial.Display.clear(); // // M5Dial.Display.drawString("LSleep_Hd", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 10); // M5Dial.Display.drawString("Touch ", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20); // delay(1000); // M5Dial.Display.clear(); // // esp_sleep_enable_ext0_wakeup(GPIO_NUM_14, LOW); // esp_light_sleep_start(); // }

//-------------- 6) To test deep sleep (ESP32 function) initiate by the button and wakeup from the TouchPad if (M5Dial.BtnA.wasPressed()) { mode = 1; M5Dial.Display.clear();

                                              M5Dial.Display.drawString("DSleep_Hd",        M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 - 10);
                                              M5Dial.Display.drawString("Touch ",           M5Dial.Display.width() / 2,           M5Dial.Display.height() / 2 + 20);
                                              delay(1000);
                                              M5Dial.Display.clear();
                                              esp_sleep_enable_ext0_wakeup(GPIO_NUM_14, LOW);
                                              esp_deep_sleep_start();
                                         }

        }

Envoyé à partir de Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows


De : felmue @.> Envoyé : Friday, February 9, 2024 7:06:43 AM À : m5stack/M5Dial @.> Cc : jsgagnon2020 @.>; Mention @.> Objet : Re: [m5stack/M5Dial] Cannot wakeup from deep sleep with WAKE button (Issue #11)

Hello @jsgagnon2020https://github.com/jsgagnon2020

I've created a simple example show-casting sleep modes and waking from touch screen or dial button.

Thanks Felix

— Reply to this email directly, view it on GitHubhttps://github.com/m5stack/M5Dial/issues/11#issuecomment-1935812736, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOLSZ7VDAH4Z4GYPIGM6C6LYSYGNHAVCNFSM6AAAAABBUIVYUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZVHAYTENZTGY. You are receiving this because you were mentioned.Message ID: @.***>

jsgagnon2020 commented 5 months ago

After more testing,

I found out that if you plug a battery in the M5Dial, the touchPad AND the button work for the deepsleep (button ONLY if the M5Dial as a battery as a power source)

Thank to all

jsgagnon2020 commented 5 months ago

Hi,

I have updated the full version of an Arduino M5dial deepsleep program on Git

By any chance, do you know if there is some possibility of getting a status of the battery connected to the M5Dial?

In documentation, they appears to say NO??

Thank, JS

Envoyé à partir de Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows


De : felmue @.> Envoyé : Friday, February 9, 2024 7:06:43 AM À : m5stack/M5Dial @.> Cc : jsgagnon2020 @.>; Mention @.> Objet : Re: [m5stack/M5Dial] Cannot wakeup from deep sleep with WAKE button (Issue #11)

Hello @jsgagnon2020https://github.com/jsgagnon2020

I've created a simple example show-casting sleep modes and waking from touch screen or dial button.

Thanks Felix

— Reply to this email directly, view it on GitHubhttps://github.com/m5stack/M5Dial/issues/11#issuecomment-1935812736, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOLSZ7VDAH4Z4GYPIGM6C6LYSYGNHAVCNFSM6AAAAABBUIVYUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZVHAYTENZTGY. You are receiving this because you were mentioned.Message ID: @.***>