<?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[Wake up (from Deep sleep) example in documentation]]></title><description><![CDATA[<p dir="auto">Could it be that there are some errors in the example script in the documentation available at <a href="https://docs.sgwireless.com/tutorials-examples/basic/sleep/" target="_blank" rel="noopener noreferrer nofollow ugc">link</a>:</p>
<pre><code>import machine
import time
wake_reason = machine.wake_reason()
print("Device running for: " + str(time.ticks_ms()) + "ms")
if wake_reason == machine.PWRON_RESET:
    print("Woke up by reset button")
elif wake_reason == machine.PIN_WAKE:
    print("Woke up by external pin (external interrupt)")
elif wake_reason == machine.ULP_WAKE:
    print("Woke up by ULP (capacitive touch)")
elif wake_reason == machine.TOUCHPAD_WAKE:
    print("Woke up by touchpad")

machine.deepsleep(1000*60) #sleep for 1 minute
print("This will never be printed")
</code></pre>
<p dir="auto">I think there is some mixup between machine.wake_reason() and  machine.reset_cause().<br />
When the F1 is woken up from deep sleep because the reset button is pressed, the wake_reason=0 and reset_cause=1<br />
When the F1 is woken up from deep sleep by an external pin (wake_on_ext0), the wake_reason=2 and reset_cause=4<br />
And since the constant machine.PWRON_RESET=2, this script will give the message “Woke up by reset button” when it was actually woken up by an external pin.  And when it is woken up by the reset button, it will not produce a message.  Because in that case wake_reason=0, so it fulfils none of the if conditions.</p>
<p dir="auto">The meaning of machine.wake_reason() and  machine.reset_cause() codes (and the definition of the constants) can be obtained by:</p>
<pre><code>&gt;&gt;&gt; import machine
&gt;&gt;&gt; help(machine)
object &lt;module 'umachine'&gt; is of type module
  __name__ -- umachine
  mem8 -- &lt;8-bit memory&gt;
  mem16 -- &lt;16-bit memory&gt;
  mem32 -- &lt;32-bit memory&gt;
  freq -- &lt;function&gt;
  reset -- &lt;function&gt;

(I dropped some lines here)

  reset_cause -- &lt;function&gt;
  HARD_RESET -- 2
  PWRON_RESET -- 1
  WDT_RESET -- 3
  DEEPSLEEP_RESET -- 4
  SOFT_RESET -- 5
  wake_reason -- &lt;function&gt;
  PIN_WAKE -- 2
  EXT0_WAKE -- 2
  EXT1_WAKE -- 3
  TIMER_WAKE -- 4
  TOUCHPAD_WAKE -- 5
  ULP_WAKE -- 6
&gt;&gt;&gt;
</code></pre>
<p dir="auto">I also do not understand why the example script reads as:</p>
<pre><code>elif wake_reason == machine.ULP_WAKE:
    print("Woke up by ULP (capacitive touch)")
</code></pre>
<p dir="auto">I would think that when the F1 is woken up by the ULP, that has nothing to do with ‘capacitive touch’. Or do I get it wrong?</p>
]]></description><link>https://forum.sgwireless.com/topic/65/wake-up-from-deep-sleep-example-in-documentation</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 13:03:15 GMT</lastBuildDate><atom:link href="https://forum.sgwireless.com/topic/65.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 May 2025 10:56:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wake up (from Deep sleep) example in documentation on Wed, 07 May 2025 12:51:42 GMT]]></title><description><![CDATA[<p dir="auto">Thanks a lot for the feedback, <a class="mention plugin-mentions-user plugin-mentions-a" href="https://forum.sgwireless.com/uid/56">@jandls</a>. This was taken straight from the old Pycom documentation and hasn’t been reviewed/updated yet.</p>
]]></description><link>https://forum.sgwireless.com/post/76</link><guid isPermaLink="true">https://forum.sgwireless.com/post/76</guid><dc:creator><![CDATA[cehlers]]></dc:creator><pubDate>Wed, 07 May 2025 12:51:42 GMT</pubDate></item></channel></rss>