ESP32GPIO唤醒使能

我想用GPIO唤醒处理器,在IDF中,功能为esp_sleep_enable_gpio_wakeup和gpio_wakeup_enable。有没有办法在Micropython中做到这一点?我已经尝试过Pin.irq函数的唤醒参数,但是它不起作用。

有朋友建议我从深度睡眠中醒来,传输消息,然后再次进入睡眠状态。btn1和btn2是簧片开关位置(磁铁靠近簧片或远离簧片)。这样,我的板就一直保持睡眠状态,并且仅在磁铁位置变化时才唤醒。

import sx127x, esp32 import cfg_lora as cfg from machine import Pin, deepsleep, wake_reason, idle from time import sleep Device = 'Balkonas' Sensor = 'Langas' # O C def transmit(Value): # payload = '{};{}:{}#Battery:3.82#Temp:23.2'.format(Device, Sensor, Value) payload = '{};{}:{}'.format(Device, Sensor, Value) lora = sx127x.SX127x(cfg.lora_spi, pins=cfg.lora_pins, parameters=cfg.lora_default) print("LoRa Started"); print(payload) lora.println(payload) led1 = Pin(2, Pin.OUT) led1.on() wakeReason = wake_reason() print('Wake Reason =', wakeReason) btn1 = Pin(32, Pin.IN, Pin.PULL_DOWN) # Normally low, high when pressed btn2 = Pin(33, Pin.IN, Pin.PULL_DOWN) # Normally low, high when pressed if( btn1.value() == 1 and btn2.value() == 0 ): Pin(32, Pin.IN, None) esp32.wake_on_ext0(pin = btn2, level = esp32.WAKEUP_ANY_HIGH) transmit("Closed") elif( btn1.value() == 0 and btn2.value() == 1 ): Pin(33, Pin.IN, None) esp32.wake_on_ext0(pin = btn1, level = esp32.WAKEUP_ANY_HIGH) transmit("Opened") else: esp32.wake_on_ext0(pin = btn1, level = esp32.WAKEUP_ANY_HIGH) esp32.wake_on_ext1(pins = (btn2, ), level = esp32.WAKEUP_ANY_HIGH) transmit("Unknown") idle() print("Waiting five seconds") sleep(5) # Do NOT remove this statement print("Going to sleep") led1.off() deepsleep()


我尝试使用ext0和ext1唤醒esp32,但我想使用任何gpio,而不仅仅是连接到RTC的gpio。使用轻度睡眠,我可以拥有更多控制权,可以使用不同的外部来源唤醒esp。https://docs.espressif.com/projects/esp ...仅睡眠我有多个外部中断在触发时触发,而使用ext0或ext1则无法做到。

请先 登录 后评论