I using firmware supplied in XIAO ESP32C6 with MicroPython | Seeed Studio Wiki
The MicroPython website does not have an alternative image.
Could there be additional setup required to get this work or a code change?
Thanks for any suggestions.
SailorMorris
# MicroPython v1.24.0-preview.407.g197becbdc on 2024-10-09;
"""
Deepsleep is NOT waking up from an external signal.
Function Purpose
-------- -------
__main__ Setup
main Verify the door_sw is working, init and enter deepsleep
new_mail_notice Report reset_cause worked in main
"""
from micropython import const
import os
import sys
import time
import machine
from time import sleep, ticks_ms, ticks_diff
from machine import Pin, UART, ADC
from esp32 import wake_on_ext1, WAKEUP_ALL_LOW
LED_PIN = const(15)
WAKE_UP_PIN = const(2) # **********
WAKE_UP_PIN_MASK = const(1 << WAKE_UP_PIN) # **********
def new_mail_notice(door_sw):
vsys = ADC(Pin(0))
vsys.atten(ADC.ATTN_11DB) # 0-3.6volt range
print(f'VSYS = {vsys.read_uv() * 2 / 1000000:02f} volts')
print(f'{door_sw.value()=}')
def main():
global WAKE_UP_PIN, WAKE_UP_PIN_MASK
door_sw = Pin(WAKE_UP_PIN, Pin.IN, Pin.PULL_UP) # ***********
print("OK, operate the switch verify the value changes.")
for _ in range(20):
print(f'Mailbox door_sw is {"Closed" if door_sw.value() else "Open"}.')
sleep(0.5)
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
new_mail_notice(door_sw)
# wake_on_ext1([WAKE_UP_PIN_MASK], (WAKEUP_ALL_LOW, )) # ***********
# wake_on_ext0(door_sw, WAKEUP_ALL_LOW) # ***********
wake_on_ext1((door_sw,), WAKEUP_ALL_LOW) # ***********
# I've tried all versions of WAKEUP_ALL_x & WAKEUP_ANY_x x=HIGH or LOW
# only the WAKEUP_ALL_LOW is accepted by the interperter.
if door_sw.value(): # default (door_sw=closed=1) to DeepSleep
print('Going into DeepSleep for maximum of 30 seconds.')
sleep(1)
machine.deepsleep(29 * 1000) # ***********
print('Past deepsleep()')
if __name__ == '__main__':
print("Entry to __main__")
led = Pin(LED_PIN, Pin.OUT, value=0) # light the LED
start = ticks_ms()
excpt_log = open('exception.txt', 'w')
try:
uart = UART(1, baudrate=115200, tx=Pin(6), rx=Pin(7))
uart.init(115200, bits=8, parity=None, stop=1)
os.dupterm(uart, 0)
main()
print(f'Runtime = {ticks_diff(ticks_ms(), start)} millisecs.')
except Exception as e:
sys.print_exception(e) # , excpt_log)
excpt_log.close()
led.value(1) # turn the LED OFF (program end)