<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5Paper wakeup cause]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm playing around with the M5Paper RTC and I'm stuck on differentiating between a restart caused by pressing the reset button, and a restart caused by a <code>shutdown()</code> with a RTC IRQ wakeup.</p>
<p dir="auto">I'm writing a simple clock application that updates once a minute with the following properties:</p>
<ul>
<li>On boot I paint a decorative frame (I actually pull it by http), connect to ntp and setup the RTC clock. Finally I draw the time, and do a <code>shutdown(60)</code> to wake up in a minute.</li>
<li>After a minute I want to wake up, draw the time, and go back to sleep.</li>
</ul>
<p dir="auto">So I did all the initialization in <code>setup()</code> and initialized the RTC, setup the font cache, and then went to sleep for 60s. But when I wake up after 60s I need to know whether the RTC has already been initialized, and whether I have already painted the clock frame. Right now I do all the setup once a minute.</p>
<p dir="auto">The ESP itself has a wake up "reason". But how would I access it on the M5Paper? And does it work in the context of the BM8563 RTC?</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://community.m5stack.com/topic/2851/m5paper-wakeup-cause</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 08:23:26 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2851.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 Jan 2021 20:37:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Paper wakeup cause on Sun, 06 Aug 2023 17:58:48 GMT]]></title><description><![CDATA[<p dir="auto">To make this detection really reliable I had to change the RTC register check like this:</p>
<pre><code>Wire.begin(21, 22);
uint8_t reason = M5.RTC.readReg(0x01);
// now it's safe
M5.begin();
// check reboot reason flag: TIE (timer int enable) &amp;&amp; TF (timer flag active)
if ((reason &amp; 0b0000101) == 0b0000101) {
    restartByRTC = true;
    Serial.println("Reboot by RTC");
} else {
    restartByRTC = false;
    Serial.println("Reboot by power button / USB");
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/21806</link><guid isPermaLink="true">https://community.m5stack.com/post/21806</guid><dc:creator><![CDATA[dheijl]]></dc:creator><pubDate>Sun, 06 Aug 2023 17:58:48 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Sat, 03 Apr 2021 06:44:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a><br />
Hello Felix,</p>
<p dir="auto">No, didn't try rename <code>rtc</code>. What difference should it make? (In C++ rtc and RTC are different identifiers, is n't it).<br />
The reason for introduction of the own internal rtc of the ESP32 was looking for a simple way to set the system clock from the M5Paper RTC after awakening and without connecting to WiFi (this is very time- and battery-consuming).</p>
<p dir="auto">The weird thing is: syncing with NTP is rather simple in ESP32-Arduino environment, but just setting the system time equal to the 'external' BM8563 RTC-time is more complicated. There is no simple routine. I found some not so elegant way with mktime().</p>
<p dir="auto">Another point: I discovered bugs with awakening the M5Paper when this awakening moment should be exactly at midnight: so at 24:00u or 00:00u.<br />
See a next post (if I find time to describe).</p>
]]></description><link>https://community.m5stack.com/post/13362</link><guid isPermaLink="true">https://community.m5stack.com/post/13362</guid><dc:creator><![CDATA[Jop]]></dc:creator><pubDate>Sat, 03 Apr 2021 06:44:13 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 30 Mar 2021 22:35:51 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/7975">@Jop</a></p>
<p dir="auto">have you tried to rename <code>rtc</code> to something else? Does that fix the issue?</p>
<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/1">@M5Stack</a> engineers : any idea what's going on here?</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13333</link><guid isPermaLink="true">https://community.m5stack.com/post/13333</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 30 Mar 2021 22:35:51 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 30 Mar 2021 19:23:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a></p>
<p dir="auto">Hi Felix,</p>
<p dir="auto">In addition to my last post, I wrote that the shutdown() looks rather buggy.</p>
<p dir="auto">Now I found reason for this behavior - <strong>partly</strong> reason - some overload variations are now OK, but one has still problem as I described in my last post.<br />
The reason for buggy behavior, I included this:<br />
<code>#include &lt;ESP32Time.h&gt;</code><br />
<code>ESP32Time rtc;</code><br />
to make it possible to set also the ESP32 internal RTC that's present in this processor, named by me with "rtc".<br />
The external BM8563 I named as "RTC".<br />
Maybe these library is interfering with the BM8563-code.</p>
<p dir="auto">I said "<strong>partly</strong> reason" as Overload-2 still has the same problem as I wrote before.</p>
]]></description><link>https://community.m5stack.com/post/13331</link><guid isPermaLink="true">https://community.m5stack.com/post/13331</guid><dc:creator><![CDATA[Jop]]></dc:creator><pubDate>Tue, 30 Mar 2021 19:23:15 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 30 Mar 2021 08:28:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a><br />
Hi Felix,</p>
<p dir="auto">Thnx for your fast response.</p>
<p dir="auto">I out commented the 2 lines you mentioned, this seems to work, but I experience more problems.<br />
This <a href="https://docs.m5stack.com/#/en/api/m5paper/system_api?id=shutdown" target="_blank" rel="noopener noreferrer nofollow ugc">shutdown() logic</a> of the M5Paper is rather buggy. I think some engineers of M5Stack should inspect this modules and repair.<br />
For example: I want my M5Paper to be waked up by the RTC every full 5 minutes, then it has to run for about 10 to 15 seconds and to go in sleepmode for the rest of that 5-minute period. For that I wrote routine goSleep() to calculate the next moment of  awakening.<br />
I tried several possibilities for the different overlaid methods of shutdown():</p>
<ol>
<li>calculate remaining seconds to  go sleep and used overload-2</li>
<li>calculate timestamp for the next 5-minute moment and used overload-3</li>
<li>calculate date &amp; timestamps for the next 5-minute moment and used overload-4</li>
</ol>
<p dir="auto">Now comes the weird thing (so the bugs), in any of these cases the wakeup comes ALSO at every 3-minute, so both at every 3-minute and at every 5-minute moments.<br />
So where I want to have this wake up schedule: hh:00  hh:05  hh:10  hh:15  hh:20 ...and so on...<br />
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...</p>
<p dir="auto">Before your suggested patch I tried only method 1 (as 2 did not work without your patch) and then it was every 4-minute and every 5-minute my M5Paper woke up by the RTC.<br />
I inspected my calculations logic and this is OK. The problem is somewhere in the M5Paper library.</p>
<p dir="auto">If necessary I can isolate the code I use to show you; but that's a bit more work.</p>
]]></description><link>https://community.m5stack.com/post/13318</link><guid isPermaLink="true">https://community.m5stack.com/post/13318</guid><dc:creator><![CDATA[Jop]]></dc:creator><pubDate>Tue, 30 Mar 2021 08:28:32 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Sat, 27 Mar 2021 06:28:42 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/7975">@Jop</a></p>
<p dir="auto">thanks for reporting back. I am happy to hear you got it working to your liking.</p>
<p dir="auto">Re shutdown: that has been fixed in a pull-request, but unfortunately M5Stack engineers are very slow lately (or no longer allowed or interested?) to approve and use pull-requests from the community.</p>
<p dir="auto">Essentially the following two lines need to be removed:</p>
<pre><code>    out_buf[2] = 0x00;
    out_buf[3] = 0x00;
</code></pre>
<p dir="auto">See <a href="https://github.com/m5stack/M5EPD/pull/22/files" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> around line 232.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13263</link><guid isPermaLink="true">https://community.m5stack.com/post/13263</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Sat, 27 Mar 2021 06:28:42 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Sat, 27 Mar 2021 04:23:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a><br />
Hi Felix,</p>
<p dir="auto">Good tip. It works.</p>
<p dir="auto">Here the update code based on an example from the M5EPD library:</p>
<pre><code>#include &lt;M5EPD.h&gt;

// m5paper-wakeup-cause
// see forum: https://community.m5stack.com/topic/2851/m5paper-wakeup-cause/6

M5EPD_Canvas canvas(&amp;M5.EPD);

void setup() {
  //  Check power on reason before calling M5.begin()
  //  which calls RTC.begin() which clears the timer flag.
  Wire.begin(21, 22);                  
  uint8_t data = M5.RTC.readReg(0x01);     
   
  M5.begin();

  bool flagRTC = false;
  
  // Check timer flag
  if ((data &amp; 0b00000100) == 0b00000100) {
    flagRTC = true;
    Serial.println("Power on by: RTC timer");
  }
  else {
    Serial.println("Power on by: PWR Btn");
  }
     
  M5.EPD.SetRotation(90);
  M5.TP.SetRotation(90);
  M5.EPD.Clear(true);
  M5.RTC.begin();
  
  canvas.createCanvas(540, 960);  
  canvas.setTextSize(3);
  if (flagRTC)
    canvas.drawString("Power on by: RTC timer", 25, 250); // &lt;= this one we should when waking up from sleep
  else  
    canvas.drawString("Power on by: PWR Btn", 25, 250);
    
  canvas.drawString("Press PWR Btn for sleep!", 45, 350);
  canvas.drawString("after 5 sec wakeup!", 70, 450);
  canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}

void loop() {
  if (M5.BtnP.wasPressed()) {      
    canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
    delay(1000);
    M5.shutdown(5); // shut donw now and wake up after 5 seconds
  }
  M5.update();
  delay(100);
}
</code></pre>
<p dir="auto">One extra remark (maybe for a new topic): the shutdown() routine has some overloaded variations. Unfortunately not very well documented, as the version with only time (see: <a href="https://docs.m5stack.com/#/en/api/m5paper/system_api?id=function-overload-3" target="_blank" rel="noopener noreferrer nofollow ugc">int shutdown( const rtc_time_t &amp;RTC_TimeStruct);</a> ) seems not to work as expected. If add the date too (last overloaded version) it works. Maybe my expectations are wrong. Sometimes one should like a bit more specifications from M5Stack in this documentation (is a timesaver).</p>
<p dir="auto">Anyway thnx for your suggestion Wire1 =&gt; Wire.</p>
]]></description><link>https://community.m5stack.com/post/13262</link><guid isPermaLink="true">https://community.m5stack.com/post/13262</guid><dc:creator><![CDATA[Jop]]></dc:creator><pubDate>Sat, 27 Mar 2021 04:23:52 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 23 Mar 2021 17:35:56 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/7975">@Jop</a></p>
<p dir="auto">thank you for trying it on an M5Paper.</p>
<p dir="auto">Try to change <code>Wire1.begin(21, 22)</code> to <code>Wire.begin(21, 22)</code>. M5Paper unlike M5CoreInk uses <code>Wire</code> for its internal I2C. And having <code>Wire</code> and <code>Wire1</code> setup to use the same set of GPIOs makes <code>M5.RTC.begin()</code> fail and thus the timer flag never gets cleared.</p>
<p dir="auto">Cheers<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13202</link><guid isPermaLink="true">https://community.m5stack.com/post/13202</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 23 Mar 2021 17:35:56 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 23 Mar 2021 16:37:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a>,</p>
<p dir="auto">Interesting post you wrote - nice solution to detect reason for awakening the M5Paper. But unfortunately the <a href="https://github.com/m5stack/M5-CoreInk/pull/6/files" target="_blank" rel="noopener noreferrer nofollow ugc">code you gave for M5Corelink</a> doesn't compile on a M5Paper.</p>
<p dir="auto">I did some trial and error modifications and within 5 minutes I got code that does compile.<br />
Here just the relevant code in <code>setup()</code>   - sketch from an example in the M5EPD library:</p>
<pre><code>#include &lt;M5EPD.h&gt;

// is not yet working as should be

M5EPD_Canvas canvas(&amp;M5.EPD);

void setup() {
  // Check power on reason before calling M5.begin()
  //  which calls Rtc.begin() which clears the timer flag.
  Wire1.begin(21, 22);                  // Jop: compiles
//uint8_t data = M5.rtc.ReadReg(0x01);  // Jop: compiles NOT
  uint8_t data = M5.RTC.readReg(0x01);  // Jop: compiles   
   
  M5.begin();

  bool flagRTC = false;
  
  // Check timer flag
  if ((data &amp; 0b00000100) == 0b00000100) {
    flagRTC = true;
    Serial.println("Power on by: RTC timer");
  }
  else {
    Serial.println("Power on by: PWR Btn");
  }
     
  M5.EPD.SetRotation(90);
  M5.TP.SetRotation(90);
  M5.EPD.Clear(true);
  M5.RTC.begin();
  
  canvas.createCanvas(540, 960);  
  canvas.setTextSize(3);
  if (flagRTC)
    canvas.drawString("Power on by: RTC timer", 25, 250); // &lt;= this one we see always
  else  
    canvas.drawString("Power on by: PWR Btn", 25, 250);
    
  canvas.drawString("Press PWR Btn for sleep!", 45, 350);
  canvas.drawString("after 5 sec wakeup!", 70, 450);
  canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}

void loop() {
  if (M5.BtnP.wasPressed()) {      
    canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
    delay(1000);
    M5.shutdown(5);
  }
  M5.update();
  delay(100);
}
</code></pre>
<p dir="auto">As you see I had to change just some capital-mode in identifiers to get it compiled.<br />
But apparently not the right register or bits are used for detecting wakeup cause.</p>
<p dir="auto">Maybe someone else is triggered by this to find the full solution for the M5Paper.</p>
]]></description><link>https://community.m5stack.com/post/13200</link><guid isPermaLink="true">https://community.m5stack.com/post/13200</guid><dc:creator><![CDATA[Jop]]></dc:creator><pubDate>Tue, 23 Mar 2021 16:37:08 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Wed, 03 Feb 2021 15:41:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/6020">@dov</a> I'm very new to the M5Paper, but I'm wondering if you couldn't use the <code>esp_deep_sleep_start()</code> instead of shutdown because this will keep the RTC going and shutdown everything else.</p>
<p dir="auto">In theory, you might be able to call <code>esp_err_tesp_sleep_enable_timer_wakeup()</code> with an appropriate duration and then simply continue. According to the documentation the Wifi connection data is kept as well.</p>
<p dir="auto">I'm currently trying to work on something like this as well.</p>
]]></description><link>https://community.m5stack.com/post/12294</link><guid isPermaLink="true">https://community.m5stack.com/post/12294</guid><dc:creator><![CDATA[grundprinzip]]></dc:creator><pubDate>Wed, 03 Feb 2021 15:41:58 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Tue, 02 Feb 2021 18:26:27 GMT]]></title><description><![CDATA[<p dir="auto">You could use the EEPROM to store the state in - e.g. last time the device went to sleep, last time NTP sync happened, etc. - and use that to decide which path of logic you need to follow.</p>
<p dir="auto">For example, this could be the full flow:</p>
<p dir="auto"><code>setup()</code>:</p>
<ol>
<li>Get EEPROM, extract last NTP sync (<code>last_ntp_sync</code>), last boot time (<code>last_boot</code>), and last requested sleep length (<code>sleep_duration</code>)</li>
<li>Get RTC time (<code>rtc_time</code>)</li>
<li>If <code>last_ntp_sync</code> is empty, go to <code>first_boot()</code></li>
<li>If <code>last_boot</code> is empty, go to <code>first_boot()</code></li>
<li>If <code>rtc_time - last_boot &lt; sleep_duration</code> (maybe add some wiggle room here, 1-2s should be fine), go to <code>manual_wakeup()</code></li>
<li>Otherwise, go to <code>rtc_wakeup()</code></li>
</ol>
<p dir="auto"><code>first_boot()</code>:</p>
<ol>
<li>Connect to WiFi</li>
<li>Request date and time from NTP = <code>new_rtc_time</code></li>
<li>Update RTC with <code>new_rtc_time</code></li>
<li>Update EEPROM's <code>last_ntp_sync</code> and <code>last_boot_time</code></li>
<li>Proceed to <code>draw_clock()</code></li>
</ol>
<p dir="auto"><code>rtc_wakeup()</code>:</p>
<ol>
<li>Check if <code>last_ntp_sync</code> is not too old (e.g. you'd probably want to sync with NTP daily)</li>
<li>If <code>last_ntp_sync</code> is too old, go to a method that syncs RTC time</li>
<li>Update EEPROM's <code>last_boot_time</code></li>
<li>Proceed to <code>draw_clock()</code></li>
</ol>
<p dir="auto"><code>manual_wakeup()</code>:</p>
<ol>
<li>Do the whole NTP check dance again (probably worth organising into a separate method)</li>
<li>Do whatever you want to do if the device wakeup happened due to the button press</li>
<li>Proceed to <code>draw_clock()</code></li>
</ol>
<p dir="auto">Obviously extend it to your liking, but by storing these values, you can compare the last stored date with the RTC time, and act accordingly. It's not as elegant as e.g. having a proper boot reason, but it works.</p>
]]></description><link>https://community.m5stack.com/post/12246</link><guid isPermaLink="true">https://community.m5stack.com/post/12246</guid><dc:creator><![CDATA[fonix232]]></dc:creator><pubDate>Tue, 02 Feb 2021 18:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper wakeup cause on Fri, 29 Jan 2021 07:50:57 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/6020">@dov</a></p>
<p dir="auto">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) <a href="https://github.com/m5stack/M5-CoreInk/pull/6/files" target="_blank" rel="noopener noreferrer nofollow ugc">here</a>.</p>
<p dir="auto">BTW: The wake up reason of the ESP32 doesn't help you here. As far as the ESP32 is concerned it's a regular start in both cases as the shutdown kills the power to the ESP32 completely. (Only when the ESP32 stays powered and goes into deep sleep or light sleep you can use the ESP32 wake up reason.)</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/12145</link><guid isPermaLink="true">https://community.m5stack.com/post/12145</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 29 Jan 2021 07:50:57 GMT</pubDate></item></channel></rss>