Trying to understand the basics of deepsleep and external interrupts #14296
Replies: 4 comments 4 replies
-
Which port/board are you using? Deepsleep isn't the same on all platforms |
Beta Was this translation helpful? Give feedback.
-
Meanwhile I have found this topic on the old forum, thanks paulg. There seems to be some interesting info in the docs (see image below) Is it correct that wake_on_ touch / ulp / ext_0 / ext1 would give four different wake up reasons? Code in forum post: # test21.py: Deepsleep and wakeup source experiments
# Copy to your ESP32 board as main.py
from machine import Pin, deepsleep, wake_reason
import esp, esp32
from time import sleep
led1 = Pin(25, Pin.OUT)
btn1 = Pin(33, Pin.IN, Pin.PULL_UP) # Normally high, low when pressed
btn2 = Pin(14, Pin.IN, Pin.PULL_DOWN) # Normally low, high when pressed
print('\nHello. This is test 21')
esp.osdebug(None)
while True:
print('Wake Reason =', wake_reason())
led1.on()
sleep(5) # Do NOT remove this statement
led1.off()
esp32.wake_on_ext0(pin = btn2, level = esp32.WAKEUP_ANY_HIGH)
esp32.wake_on_ext1(pins = (btn1, ), level = esp32.WAKEUP_ALL_LOW)
deepsleep(9000) |
Beta Was this translation helpful? Give feedback.
-
Based on what I found I wrote the test code below. But what does this mean: "Pin(s) can be None"? Thanks '''
Code to test wake_reason on ESP32-S3
MicroPython v1.22.2 on 2024-02-22; Generic ESP32S3
Reason
0 Normal boot / power on
1 Unknown
2 EXT0 - Single pin
esp32.wake_on_ext0(pin = btn, level = esp32.WAKEUP_ALL_LOW)
Pin can be None or a valid Pin object.
Level should be esp32.WAKEUP_ALL_LOW or esp32.WAKEUP_ANY_HIGH.
3 EXT1 - Multiple pins
esp32.wake_on_ext1(pins = [btn1, btn2], level = esp32.WAKEUP_ALL_LOW)
Pins can be None or a tuple/list of valid Pin objects.
Level should be esp32.WAKEUP_ALL_LOW or esp32.WAKEUP_ANY_HIGH.
4 Timer wake up
'''
from machine import Pin, deepsleep, wake_reason
from time import sleep_ms as sms
import esp32
led = Pin(21, Pin.OUT)
btn = Pin( 3, Pin.IN, Pin.PULL_UP)
esp32.wake_on_ext0(pin = btn, level = esp32.WAKEUP_ALL_LOW)
def blink(n):
t=1000 if n==0 else 200
if n==0: n=1
for b in range(n):
led.value(0); sms(t)
led.value(1); sms(t)
blink(wake_reason())
deepsleep(20000) |
Beta Was this translation helpful? Give feedback.
-
I tend to use flash for stuff that is used infrequently. In the old days we
were told not to hammer flash cycle after cycle for fear of wearing it out.
These days with modern wear levelling algorithms who knows.
…On Mon, 15 Apr 2024, 12:40 am MrTinkerman, ***@***.***> wrote:
Thanks for the tip on RTC versus flash, so if I want to be sure to get my
data after a deepsleep, I should use flash right?
Using the ulp looks a bit beyond my skill level.
—
Reply to this email directly, view it on GitHub
<#14296 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AV562M6MTRUYIDWOGX75QEDY5KINNAVCNFSM6AAAAABGFQ6AG6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCMBZG4ZDC>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hi,
TLDR: Can you add callbacks to interrupts that wake a board up from deepsleep?
I'm trying to learn more about using deepsleep and using external interrupts. I feel like I'm missing some basic understanding and hope someone can explain.
Edit: Board info
XIAO ESP32-S3 with MicroPython v1.22.2 on 2024-02-22; Generic ESP32S3
Say you put your board in deepsleep and set 2 interrupts, say 2 buttons, to wake it up from deepsleep.
Can callbacks be added to those interrupts to know which button caused the interrupt?
As far as I understand the board is reset when coming from deepsleep, so after a reset all info on which button caused the interrupt will be gone right? On the old forum I found this topic about storing data in the RTC memory. I have not tried this but even if it works, the data would have to be stored right after the interrupt?
If anyone can point me to some 'explain it to me like I'm 5' information on this topic, please let me know.
All I can find are half baked tutorials and I dont trust chatgpt one bit on this.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions