How should I resume work after calling M5.shutdown()?



  • I modified the RTC example for the M5Paper to call M5.shutdown instead of delay. However, when I do this, the time is no longer written to the screen. If the device is plugged into a computer, the screen is correctly updated (but I think this is because M5.shutdown has no effect when plugged into power).

    Is there some change I need to make to correctly resume work after calling M5.shutdown()?

    #include <M5EPD.h>
    
    M5EPD_Canvas canvas(&M5.EPD);
    
    rtc_time_t RTCtime;
    rtc_date_t RTCDate;
    
    char timeStrbuff[64];
    
    void flushTime(){
        M5.RTC.getTime(&RTCtime);
        M5.RTC.getDate(&RTCDate);
        
        sprintf(timeStrbuff,"%d/%02d/%02d %02d:%02d:%02d",
                            RTCDate.year,RTCDate.mon,RTCDate.day,
                            RTCtime.hour,RTCtime.min,RTCtime.sec);
                                             
        canvas.drawString(timeStrbuff, 0, 0);
        canvas.pushCanvas(100,200,UPDATE_MODE_DU4);
    }
    
    void setupTime(){
      
      RTCtime.hour = 17;
      RTCtime.min = 47;
      RTCtime.sec = 0;
      M5.RTC.setTime(&RTCtime);
      
      RTCDate.year = 2021;
      RTCDate.mon = 2;
      RTCDate.day = 7;
      M5.RTC.setDate(&RTCDate);
    }
    
    void setup() {
    
        M5.begin();
        M5.EPD.SetRotation(90);
        M5.EPD.Clear(true);
        M5.RTC.begin();
        canvas.createCanvas(400, 300);
        canvas.setTextSize(3);
        setupTime();
    }
    
    void loop() {
      flushTime();
      M5.shutdown(60);
    }
    


  • Hello @dstaley

    you are correct, when M5Paper is running from USB M5.shutdown() has no effect.

    When M5Paper runs from battery and you call M5.shutdown(60) that means everything (including the ESP32) is powered down. The only exception is the RTC clock chip which will power on M5Paper after 60 seconds. The program flow does not continue after M5.shutdown() but starts from the top, eg. setup() is run again. That is why is seem as time stands still.

    The trick is to know the reason the program got started, eg. by power button or by RTC clock. With that knowledge different things can be done in setup().

    The RTC clock has a timer flag which when set tells you that the RTC timer has woken M5Paper; if not set then it was a regular restart. I've implemented that for M5CoreInk (which has a similar architecture) here.

    Good luck!

    Thanks
    Felix



  • @felmue said in How should I resume work after calling M5.shutdown()?:

    Hello @dstaley

    you are correct, when M5Paper is running from USB M5.shutdown() has no effect.

    When M5Paper runs from battery and you call M5.shutdown(60) that means everything (including the ESP32) is powered down. The only exception is the RTC clock chip which will power on M5Paper after 60 seconds. The program flow does not continue after M5.shutdown() but starts from the top, eg. setup() is run again. That is why is seem as time stands still.

    The trick is to know the reason the program got started, eg. by power button or by RTC clock. With that knowledge different things can be done in setup().

    The RTC clock has a timer flag which when set tells you that the RTC timer has woken M5Paper; if not set then it was a regular restart. I've implemented that for M5CoreInk (which has a similar architecture) here.

    Good luck!

    Thanks
    Felix

    Hi Felix! Thanks for the information, but I'm still unclear as to why my program doesn't continually update the display. If it's running though setup() every time, shouldn't it be initializing the clock to the same time and drawing to the screen? When I run this program, the time is written once, and then the screen is cleared and it's not written to again.



  • Hello @dstaley

    Correct, that is what should happen. But yes, when I run your code I can see that the screen gets cleared but no time is shown.

    Here is why: the ePaper needs some time to actually do the writing on screen. When the pushCanvas() call returns, the actual writing is still ongoing, but in your case the system is shutdown immediately after and before the ePaper had a chance to finish. Therefore the time is not shown. The trick is to add a delay before the shutdown. I tried with a delay(1000) and now the time shows.

    Cheers
    Felix