ESP32 confusing interrupt behavior

Bilal_azhar
Posts: 1
Joined: Sun Jul 09, 2023 7:33 pm

ESP32 confusing interrupt behavior

Postby Bilal_azhar » Sun Jul 09, 2023 7:52 pm

Hi! The hardware I am using is an esp32-cam AI thinker board and a SR602 PIR motion sensorhttps://www.sinoning.com/hc-sr602-datasheet/. The output pin is connected to the ground with a 10K resistor

My objective is to wake up the esp32 from deep sleep whenever the sensor output voltage drops from 3.3v to 0. I have tested my setup the sensor works properly it outputs 3,3v across the 10k resistor when I move my hand over it and the esp32 wake-ups when I connect GPIO 13 to the ground (esp32 wakes up).

The problem I am facing is that when I connect my sensor output to GPIO 13 things don't make sense, from what I understand the device should only wake up when the sensor changes voltage from 3,3 to GND. This doesn't seem to be the case the esp32 keeps waking up randomly in 1-2 seconds after the deep_sleep start function is called. I thought maybe something is wrong with the sensor so I connected the GPIO 13 straight to GND and that shouldn't trigger the wake interrupt right? But I am seeing the same behaviour. Can anyone help figure out what's wrong?
  1. #define MOTION_WAKEUP_PIN 13
  2.  
  3. void gpio_init(gpio_int_type_t INTR_MODE, gpio_mode_t PIN_MODE , gpio_pull_mode_t UP_MODE , gpio_pull_mode_t DOWN_MODE, u_int32_t PIN)
  4. {
  5.     gpio_config_t io_config;
  6.     io_config.intr_type = INTR_MODE;
  7.     io_config.mode = PIN_MODE;
  8.     io_config.pull_up_en = UP_MODE;
  9.     io_config.pull_down_en = DOWN_MODE;
  10.     io_config.pin_bit_mask = 1ULL << PIN;
  11.     gpio_config(&io_config);
  12. }
  13.  
  14. void app_main(void)
  15. {
  16.     //Initialize NVS
  17.     esp_err_t ret = nvs_flash_init();
  18.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  19.       ESP_ERROR_CHECK(nvs_flash_erase());
  20.       ret = nvs_flash_init();
  21.     }
  22.     ESP_ERROR_CHECK(ret);
  23.  
  24.     ESP_LOGI(wifi_TAG, "ESP_WIFI_MODE_STA");
  25.     wifi_init_sta();
  26.  
  27.     gpio_init(GPIO_INTR_NEGEDGE,GPIO_MODE_INPUT,GPIO_PULLUP_ENABLE,GPIO_PULLDOWN_DISABLE,MOTION_WAKEUP_PIN);
  28.  
  29.     while(1){
  30.  
  31.         vTaskDelay(5000 / portTICK_RATE_MS);
  32.         esp_deep_sleep_start();
  33.  
  34.     }
  35.  
  36. }

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 confusing interrupt behavior

Postby ESP_Sprite » Mon Jul 10, 2023 1:58 am

Hard to say. Do you have an oscilloscope so you can look at the signals the PIR sensor outputs? Perhaps it somehow has spikes that confuse the wakeup mechanism.

MicroController
Posts: 1736
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 confusing interrupt behavior

Postby MicroController » Mon Jul 10, 2023 5:29 pm

You don't seem to have set up/enabled any wake-up source.

Who is online

Users browsing this forum: No registered users and 122 guests