Arduino ESP32 通过定时器(Timer)功能唤醒深度睡眠


通过定时器功能,设置5秒,时间到就唤醒深度睡眠

实例代码

/*通过定时器功能唤醒深度睡眠(设置为5秒)
*/#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  (5)        //时间ESP32将转入休眠状态(以秒为单位)RTC_DATA_ATTR int bootCount = 0;/*Method to print the reason by which ESP32has been awaken from sleep
*/
void print_wakeup_reason() {esp_sleep_wakeup_cause_t wakeup_reason;wakeup_reason = esp_sleep_get_wakeup_cause();switch (wakeup_reason){case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("使用 RTC_IO 的外部信号引起的唤醒"); break;case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("使用 RTC_CNTL 的外部信号引起的唤醒"); break;case ESP_SLEEP_WAKEUP_TIMER : Serial.println("定时器引起的唤醒"); break;case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("触摸板引起的唤醒"); break;case ESP_SLEEP_WAKEUP_ULP : Serial.println("ULP 程序引起的唤醒"); break;default : Serial.printf("唤醒不是由深度睡眠引起的: %d\n", wakeup_reason); break;}
}void setup() {Serial.begin(115200);delay(1000); //花一些时间打开串行监视器//增加引导编号并在每次重启时打印++bootCount;Serial.println("Boot number: " + String(bootCount));//Print the wakeup reason for ESP32print_wakeup_reason();/*First we configure the wake up sourceWe set our ESP32 to wake up every 5 seconds*/esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +" Seconds");/*Next we decide what all peripherals to shut down/keep onBy default, ESP32 will automatically power down the peripheralsnot needed by the wakeup source, but if you want to be a poweruserthis is for you. Read in detail at the API docshttp://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.htmlLeft the line commented as an example of how to configure peripherals.The line below turns off all RTC peripherals in deep sleep.*///esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);//Serial.println("Configured all RTC Peripherals to be powered down in sleep");/*Now that we have setup a wake cause and if needed setup theperipherals state in deep sleep, we can now start going todeep sleep.In the case that no wake up sources were provided but deepsleep was started, it will sleep forever unless hardwarereset occurs.*/Serial.println("要休眠了");Serial.flush();esp_deep_sleep_start();Serial.println("这永远不会被打印");
}void loop() {}
  • 串口打印

Arduino ESP32 通过定时器(Timer)功能唤醒深度睡眠相关推荐

  1. Arduino ESP32:测试GPIO中断功能

    Arduino ESP32:测试GPIO中断功能 ESP32:测试GPIO中断功能 实例代码 /*测试GPIO中断功能接线说明: 按键1接23,按键2接18 */#include <Arduin ...

  2. 学习arduino esp32相关例程(1)深度睡眠与唤醒

    我们的代码逻辑就是   开机setup   打印出唤醒原因   esp_deep_sleep_start();  唤醒原因一般有ext0  ext1  timer  touchpad  ulp  大致 ...

  3. Arduino ESP32深度睡眠触摸唤醒(触摸唤醒)

    Arduino ESP32深度睡眠触摸唤醒(触摸唤醒) 通过D4–GPIO4引脚触摸感应,触发唤醒功能. 睡眠模式下,触摸中断响应流程图 实例代码 /*深度睡眠触摸唤醒(触摸T0唤醒) */#defi ...

  4. Arduino ESP32 深度睡眠与外部唤醒(EXT0)

    Arduino ESP32 深度睡眠与外部唤醒(EXT0) 使用10K下拉电阻连接到按钮 GPIO 4和GND之间,防止其他杂波信号干扰,在3.3V和GPIO4之间接按键,用来触发EXT0,接线示意图 ...

  5. Arduino ESP32定时器功能使用

    Arduino ESP32定时器功能使用 ESP32硬件定时器介绍 ESP32 芯片包含两个硬件定时器组.每组有两个通用硬件定时器.它们都是基于 16 位预分频器和 64 位自动重载功能的向上/向下计 ...

  6. Esp32-C3使用gpio唤醒深度睡眠,rtc gpio0~5始终置低,导致低电平唤醒一直复位,高电平唤醒无效?

    Esp32-C3使用gpio唤醒深度睡眠,rtc gpio0-5始终置低,导致低电平唤醒一直复位,高电平唤醒无效? 为省电环保,需要让芯片进入深度睡眠,然后在需要时唤醒它,而不是复位重启 我使用vsc ...

  7. micro-ros arduino esp32 ros2 笔记

    micro-ros micro-ros arduino 22-05-25 github.com/micro-ROS/micro_ros_arduino/releases v2.0.5 humble g ...

  8. Java多线程学习笔记20之定时器Timer

    详细代码见:github代码地址 本节内容: 定时器Timer的使用及分析 1) 如何实现指定时间执行任务 2) 如何实现按指定周期执行任务 第五章 定时器Timer 定时/计划功能在移动开发领域使用 ...

  9. Java定时器Timer

    Java定时器Timer 在JDK库中,Timer类主要负责计划任务的功能,也就是在指定的时开始执行某一个任务.Timer类的主要作用就是设置计划任务,但封装任务的类却是TimerTask类,执行计划 ...

最新文章

  1. Android shape 绘制左右 或者上下的渐变色
  2. PE学习(五)导出表,编写DLL及查看DLL的导出信息
  3. 【杂谈】梦想与饼干,AI是你的谁?
  4. 静态Include和动态Include测试并总结
  5. javase哪部分最难_高中物理哪部分最难?这里有答案和方法!一定要收藏
  6. 程序员35岁之后的出路_35岁的程序员走向何方?
  7. Windows PowerShell 语言快速参考
  8. python中result的用法_Python中qutip用法示例详解
  9. Bitdefender 发布GandCrab V5.2勒索病毒解密工具
  10. Sematic库系列一
  11. 监控摄像头角度范围计算方法
  12. 匠心独运解读Mybatis源码,纯手工打造开源框架
  13. java学习笔记第三周(二)
  14. Halcon 排线检测|固定颜色检测
  15. java中 数组声明,java数组声明格式
  16. 大數據環境搭建,數據採集,數倉環境準備(hive on spark) 01
  17. php不能上传doc文件,PHPCMS不能上传WORD、EXCEL等文件的问题
  18. AI人工智能分析-人脸识别和分析(人脸检测跟踪、获取特征长度、提取用于人脸特征、比较相似度)
  19. Windows+Linux等双系统的卸载
  20. Mysql基础-------初识数据库,三大范式

热门文章

  1. 高德百度地图如何获取附近小区酒店银行等?
  2. Bryntum Gantt 5.2.2 New-Crack
  3. Java final String类的详细用法还有特性说明,自己也在学习.
  4. CSS实现长宽比的几种方案,CSS如何实现长宽比?
  5. html打开ppt自动播放,ppt文件怎么打开就可以全屏自动播放
  6. [1][python基础]条件判断[4]
  7. 2019暑假找实习工作经历-我太难了
  8. QLabel setText 标红 加粗
  9. 【webGoat】Path traversal
  10. poi 颜色对照表