- void IRAM_ATTR rainTip() { //tip is 30ms wide LOW pulse
- portENTER_CRITICAL(&mux);
- ++tips;
- rtc_gpio_deinit(GPIO_NUM_13);
- portEXIT_CRITICAL(&mux);
- }
- void setup (void)
- {
- Serial.begin(115200);
- delay (500);
- pinMode(rcvTip, INPUT);
- attachInterrupt (digitalPinToInterrupt(rcvTip), rainTip, FALLING);
- gpio_wakeup_enable((GPIO_NUM_13),GPIO_INTR_LOW_LEVEL); //Low on GPIO_13 allows interrupt
- esp_sleep_enable_gpio_wakeup();
- }
- void loop() {
- Serial.println(“Total tips = ” + String(tips));
- delay(100);
- esp_sleep_enable_timer_wakeup(10*1e6); //
- esp_light_sleep_start(); //Cannot use deep_sleep with GPIO_interrupt API per Espressif
- Serial.println(“End of Loop”);
- }
After a bucket tip, I get multiple interrupts (erratically) instead of just one per bucket tip. I have checked interrupt signal with ‘scope and only see one interrupt pulse.
I suspect the gpio_wakeup command is not used properly.
I changed the portEnter/Exit statements in the ISR to portENTER_CRITICAL_ISR(&mux) ;and
portEXIT_CRITICAL_ISR(&mux); These changes helped. It is more stable. Now I get exactly two additional delayed interrupts for a total of three. However, should only see one interrupt.
Must be additional problems in the software.
Thanks for input, Sara. Changing the ISR statements really helped. Now, I have a basic logic error in the program. The interrupt is correctly logged and then the program incorrectly goes through the Loop twice more, each time adding one more bogus tip. I need to fix this and should be able to do it.
Basic question is how does “gpio_wakeup_enable” command interact with ESP32 that is in timer sleep mode?
Hi Ron.
Accordingly to the documentation, it seems that you’re using GPIO wake up properly: https://github.com/espressif/esp-idf/blob/master/docs/en/api-reference/system/sleep_modes.rst#gpio-wakeup-light-sleep-only
Have you tried putting all you code that goes in the loop into the setup() and see what happens? Like putting your timer wake up in the setup()?
I’m not very familiar with light sleep, so I’m not sure if there’s something that is interfering with the interrupt.
When it comes to the timer wake up I’m not sure if it resets or if it continues “counting” the time for the next wake up.
Regards,
Sara
I will try putting all of the code in setup. This is required for Deep Sleep but not for Light sleep. However, it is worth a tryt.
There must be a standard way of dealing with interrupts while an esp32 is in sleep mode. This seems like a common problem.
Hi.
I know that for light sleep you can put code in the loop. When the ESP32 wakes up, it goes back to where it left in the code. However, I don’t know what happens if you put everything in the setup(). Does it still detect interrupts? It should because they are in the setup.
I haven’t experimented with interrupts while in light sleep mode, so I don’t know what might be the problem.
I’m sorry that I can’t help much.
If you find out something, please share.
Regards,
Sara
Sara, the ULP cpu on the esp32 looks perfect for my application. It can record bucket tips while the esp32 is in deep sleep. No need for interrupts!
Maybe Rui can do a tutorial on the ULP sometime. It looks pretty difficult for me to use but will try. I can think of other applications for it.