- ▷ #TSCLab #TCLab #ESP32 #Arduino #Control #MACI
- Repositories
- When using this resource, please cite the original publication:
En el siguiente blog se presenta la trigésima quinta práctica del laboratorio de control de temperatura y velocidad de un motor.
Objetivo general:
- Establecer el modo de suspensión profunda al TSC-Lab.
Materiales:
- TSC-Lab
Introducción:
Una de las formas más fáciles para para el ahorro de energía de manera general dentro de proyectos IOT es estableciendo el modo de suspensión profunda del ESP-32. En la presente práctica se colocorá el microcontrolador del TSC-Lab en sueño profundo (deep sleep) y se lo despertará con un temporizador. Cabe recalcar que existen más alternativas para despertarlo, entre ellas está el despertador táctil, externo y por URL.
Procedimiento:
Nota: se asume que todas las librerías han sido previamente instaladas.
- Copiar y cargar el siguiente código al TSC-Lab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
****************************** TSC-Lab ******************************* | |
***************************** PRACTICE 35 **************************** | |
This practice is about Deep sleep | |
By: Kevin E. Chica O | |
Reviewed: Víctor Asanza | |
More information: https://tsc-lab.blogspot.com/ | |
More examples: https://github.com/vasanza/TSC-Lab | |
Dataset: http://ieee-dataport.org/4138 | |
*/ | |
//temperaure | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
//GPIO pin 0 is set as OneWire bus | |
OneWire ourWire1(0); | |
//GPIO pin 4 is set as OneWire bus | |
OneWire ourWire2(4); | |
//A variable or object is declared for our sensor 1 | |
DallasTemperature sensors1(&ourWire1); | |
//A variable or object is declared for our sensor 2 | |
DallasTemperature sensors2(&ourWire2); | |
//deep sleep | |
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ | |
#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ | |
RTC_DATA_ATTR int bootCount = 0; | |
/* | |
Method to print the reason by which ESP32 | |
has 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("Wakeup caused by external signal using RTC_IO"); break; | |
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; | |
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; | |
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; | |
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; | |
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break; | |
} | |
} | |
void setup() { | |
Serial.begin(115200); | |
delay(1000); //Take some time to open up the Serial Monitor | |
sensors1.begin(); //Sensor 1 starts | |
sensors2.begin(); //Sensor 2 starts | |
//Increment boot number and print it every reboot | |
++bootCount; | |
Serial.println("Boot number: " + String(bootCount)); | |
//Print the wakeup reason for ESP32 | |
print_wakeup_reason(); | |
/* | |
First we configure the wake up source | |
We 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"); | |
//function for reading temperatures | |
readTemperature(); | |
Serial.println("Going to sleep now"); | |
delay(1000); | |
Serial.flush(); | |
esp_deep_sleep_start(); | |
Serial.println("This will never be printed"); | |
} | |
void loop() { | |
//This is not going to be called | |
} | |
void readTemperature() { | |
//The command is sent to read the temperature | |
sensors1.requestTemperatures(); | |
//Obtain the temperature in ºC of sensor 1 | |
float temp1 = sensors1.getTempCByIndex(0); | |
//The command is sent to read the temperature | |
sensors2.requestTemperatures(); | |
//Obtain the temperature in ºC of sensor 2 | |
float temp2 = sensors2.getTempCByIndex(0); | |
//print to display the temperature change | |
Serial.println(); | |
Serial.println("Temperatures:"); | |
Serial.print(temp1); | |
Serial.print(","); | |
Serial.println(temp2); | |
} |
Repositories: https://github.com/vasanza/TSC-Lab/tree/main/Practice35
El monitor serial mostrará algo parecido a lo siguiente:
Comments
Post a Comment