HoldPinStatus.ino 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Hold GPIO status in deep sleep mode, use ESP32's ULP (Ultra Low Power) coprocessor
  3. *
  4. * HelTec AutoMation, Chengdu, China.
  5. * 成都惠利特自动化科技有限公司
  6. * www.heltec.cn
  7. * support@heltec.cn
  8. *
  9. *this project also release in GitHub:
  10. *https://github.com/HelTecAutomation/ESP32_LoRaWAN
  11. */
  12. #include "soc/rtc_io_reg.h"
  13. #include "driver/rtc_io.h"
  14. #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
  15. #define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */
  16. RTC_DATA_ATTR int bootCount = 0;
  17. void setup(){
  18. rtc_gpio_hold_dis(GPIO_NUM_25);
  19. pinMode(25,OUTPUT);
  20. digitalWrite(25,LOW);//The on board LED will be OFF in wake up period
  21. Serial.begin(115200);
  22. delay(1000); //Take some time to open up the Serial Monitor
  23. //Increment boot number and print it every reboot
  24. ++bootCount;
  25. Serial.println("Boot number: " + String(bootCount));
  26. delay(2);
  27. esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  28. Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
  29. " Seconds");
  30. delay(10);
  31. Serial.println("Going to sleep now");
  32. delay(2);
  33. rtc_gpio_init(GPIO_NUM_25);
  34. pinMode(25,OUTPUT);
  35. digitalWrite(25,HIGH);//The on board LED will be ON in deep sleep period
  36. rtc_gpio_hold_en(GPIO_NUM_25);
  37. esp_deep_sleep_start();
  38. Serial.println("This will never be printed");
  39. }
  40. void loop(){
  41. //This is not going to be called
  42. }