Repository navigation
|
Hello everyone, I am designing a battery-powered wireless seat monitoring device based on the ESP32-C6-MINI-1-N4. The device has two independent dry-contact inputs:
Both contacts can change between open and closed states. The device must detect changes in both directions and transmit the updated status to a gateway using ESP-NOW. Intended operating sequence
Questions
Development environmentWe intend to develop the firmware using PlatformIO with the Arduino-ESP32 framework. The firmware is currently in the design phase; we have not yet created the ESP32-C6 PlatformIO project. Our main priority is reliable input-state detection with very low average power consumption. In particular, we would like to understand whether deep sleep with EXT1 is sufficient for this application, or whether an external event-latching circuit would be recommended to guarantee that contact transitions are not missed. Thank you for your help. |
Replies: 1 comment 1 reply
|
Deep sleep with EXT1 is enough for this, and the "wake on the opposite level" pattern takes care of missed transitions. Going through your questions, with references to 1. Two inputs on EXT1: yes. On the ESP32-C6, EXT1 can watch any of GPIO0–GPIO7 (the LP GPIOs), as many as you like. 2. Different levels per pin: yes, the C6 supports a level per pin. 3. Both transitions: yes, reconfigure on every wake. Read each contact, then arm it to wake on the opposite level of what you just read. Every change in either direction becomes a wake-up. 4. EXT1 plus the timer: yes, enable both. After waking, use 5. Which GPIOs: only GPIO0–7 can do EXT1. Of those, GPIO4 and GPIO5 are strapping pins (the C6 strapping pins are GPIO4, 5, 8, 9 and 15), so a contact that happens to be closed at power-up could change the boot mode. GPIO2 and GPIO3 (or 6 and 7) are good choices. 6. Pull resistors: the API notes say internal pulls only work in sleep if the RTC peripherals stay powered, or else they're kept through the pad hold feature. For a battery seat sensor I'd use external high-value pull-ups (e.g. 1 MΩ). A contact can stay closed for hours, and all that time it draws current through the pull-up, so a weak external one costs far less than the internal one. 7. Not missing a change: EXT1 is level-triggered, which is what makes this safe. If a contact changes between your read and A sketch of the sleep side: #include "esp_sleep.h"
constexpr gpio_num_t SEAT = GPIO_NUM_2; // external pull-up, contact to GND
constexpr gpio_num_t BELT = GPIO_NUM_3;
void sleepUntilNextChange() {
esp_sleep_disable_ext1_wakeup_io(0); // clear the previous configuration
// Wake when each input reaches the level it isn't at now
esp_sleep_enable_ext1_wakeup_io(1ULL << SEAT, digitalRead(SEAT) ? ESP_EXT1_WAKEUP_ANY_LOW : ESP_EXT1_WAKEUP_ANY_HIGH);
esp_sleep_enable_ext1_wakeup_io(1ULL << BELT, digitalRead(BELT) ? ESP_EXT1_WAKEUP_ANY_LOW : ESP_EXT1_WAKEUP_ANY_HIGH);
esp_sleep_enable_timer_wakeup(30ULL * 1000000); // 30 s supervision message
esp_deep_sleep_start();
}On wake, check With PlatformIO, make sure the platform you pick actually ships Arduino-ESP32 3.x. The C6 and these sleep APIs need the ESP-IDF 5.x-based core. |
Deep sleep with EXT1 is enough for this, and the "wake on the opposite level" pattern takes care of missed transitions. Going through your questions, with references to
esp_sleep.hin ESP-IDF 5.5, which Arduino-ESP32 3.x is built on:1. Two inputs on EXT1: yes. On the ESP32-C6, EXT1 can watch any of GPIO0–GPIO7 (the LP GPIOs), as many as you like.
2. Different levels per pin: yes, the C6 supports a level per pin.
esp_sleep_enable_ext1_wakeup_with_level_mask()still works but is deprecated. The replacement isesp_sleep_enable_ext1_wakeup_io(mask, mode), called once per pin with that pin's own mode.3. Both transitions: yes, reconfigure on every wake. Read each contact, then arm it to wake …