M5Paper Shutdown() / Deep Sleep / Wakeup

  • I had thought to use the M5.shutdown() as a means of timing or delaying between processes. I thought that's how some of the remote sensors were done. Sleep for one minute, wake up, get the weather and stock data (sensor data) and display it or process it, and then go back to sleep, but with it being ignored when plugged in versus not, it's not viable way to do it. I thought oh this will be easy and will help me avoid all the "blink without delay" approach to delaying between processes, but I was wrong. When my device was plugged in, I was getting weather and stock every 5 seconds. Doh! I don't doubt, it all lies in my inexperience. This post and your comments are very helpful in my finding the best approach though. I need to read up and see if you can check to see if you're powered by the battery or by the USB and maybe switch between the two methods, but there again, if one method works for both scenarios, maybe just stick with it.

  • Hello @ksprayberry

    AFAIK the M5Paper power architecture doesn't allow to tell whether the device is powered by USB or by battery. If you have a solution I'd be interested to hear about.


  • @felmue Thanks for the explanation, I have come to a similar conclusion regarding the M5.shutdown() call as well :) However, this post was stuck somewhere in an approval queue so I didn't reply earlier.

    Thanks again!

  • Hello @grundprinzip

    no worries. Thank you for sharing your conclusion. I appreciate it.


  • Hi,
    I'm currently using this small work-around to differenciate the power source between battery and USB.
    It basically involves monitoring the voltage after initializing M5.BatteryADCBegin() (via M5.getBatteryVoltage() to be more precise). Measuring a voltage over 4200 mV (empirically evaluated!) indicates most of the time a USB-usage. Under that value, there are high chances that the device is on battery.
    So far, this work-around is doing its job pretty well for me.
    I hope it might help!

  • @felmue , I tried your proposal with Arduino IDE and my M5Stack Paper:


    but get an error :

    invalid conversion from 'int' to 'gpio_num_t' [-fpermissive]

    Whats going wrong?


  • Hello @middelbeek

    sorry about that. Try:

        gpio_hold_en((gpio_num_t) M5EPD_MAIN_PWR_PIN);


  • @felmue Super, now it works! Thanks, Hans

  • Hello @middelbeek

    Thank you for reporting back. I am glad to hear you got it working.


  • As I promised here at end of my post under another thread, the shutdown() is rather buggy in the way awakening is performed.
    I'll describe here what I experienced.

    Anyway one should take this advice of @felmue in account.
    There are different shutdown() overload variations and here bugs or weird things I found.

    My goal was holding the M5Paper as much as possible sleeping, but at intervals of every full 5 minutes he should awake for about 10 to 15 seconds, perform some tasks (sensors) and go again sleeping to the next full 5-minute moment.

    • overload-2 int shutdown( int seconds );
      Even if I calc enough seconds to next 5-minute moment, it seems impossible to stay asleep for remaining 5 minutes. Every 3th minute it is awakening too. This consumes unnecessary double battery power.
      So where I want to have this wake up schedule: hh:00 hh:05 hh:10 hh:15 hh:20 ...and so on...
      I get this wake up schedule: hh:00 hh:03 hh:05 hh:08 hh:10 hh:13 hh:15 hh:18 hh:20 ...and so on...
      This overload-2 has no problems by passing the midnight moment.

    • overload-3
      int shutdown( const rtc_time_t &RTC_TimeStruct );
      This variation works best. Passing midnight (so date change) is no problem but 24:00u should be given als 00:00u.

    • overload-4
      int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct );
      is working, but passing midnight in a way to set awake time at 00:00h and increasing the date-parameter does NOT work! Also 24:00u without increasing the date does NOT work.
      The only way to pass midnight is awaking just some seconds before midnight and stay awake till after midnight, do the things that has to be done (sample sensors) and go asleep for remaining period (in my case to 00:05u).

    I hope others can take advantage of this info.