amc2022:grouph:here
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| amc2022:grouph:here [2022/08/10 12:13] – created gustavo001 | amc2022:grouph:here [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | ====== | + | {{ : |
| - | ====== | + | //**figure 4.1**// Deep-Sleep set up for ESP32/ |
| + | ====== | ||
| + | |||
| + | {{ : | ||
| + | //**figure 4.2**// Graph depicting Deep-Sleep schematics set up for ESP32/ | ||
| + | |||
| + | |||
| + | ====== | ||
| + | |||
| + | <code c++> | ||
| + | |||
| + | *//There are 2 ways to wake up a system, those are called Interrupts. | ||
| + | *//hardware Interrupts are based on external events where signals are sent to the GPIO. | ||
| + | *//Software Interrupts occur when we program the device, like through a wake up alarm or timer. | ||
| + | |||
| + | #define uS_TO_S_FACTOR 1000000 | ||
| + | #define TIME_TO_SLEEP | ||
| + | |||
| + | RTC_DATA_ATTR int bootCount = 0; | ||
| + | |||
| + | *//Data has to be stored in the Real time Clock (RTC) fast memory because the CPU memory is wiped on every boot. | ||
| + | *// The amount of data has to be minimal due to size limitations : 8bit fast memory and 8bit Slow memory. | ||
| + | |||
| + | *//Power outages and resetting the board will erase the RTC memory, therefore its use should be limited to non essential information. | ||
| + | *// | ||
| + | |||
| + | |||
| + | |||
| + | **************Wake Up Print ************************************************************** | ||
| + | |||
| + | 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(" | ||
| + | case ESP_SLEEP_WAKEUP_TIMER : Serial.println(" | ||
| + | default : Serial.printf(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | *//We made the system wake up due to the internal timer and a pushed button, | ||
| + | *// the reason for the push button is that in the case we can take a measurement at our will without having to wait for the timers. | ||
| + | *//An external clock could be added to the device, however Grafana already designates time and date of transferred data. | ||
| + | |||
| + | void setup(){ | ||
| + | Serial.begin(115200); | ||
| + | delay(1000); | ||
| + | |||
| + | pinMode(32, | ||
| + | |||
| + | pinMode(33, | ||
| + | |||
| + | | ||
| + | *//it avoids the use of external resistors | ||
| + | | ||
| + | | ||
| + | |||
| + | |||
| + | |||
| + | for(int i=0; | ||
| + | { | ||
| + | digitalWrite(32, | ||
| + | delay(1000); | ||
| + | digitalWrite(32, | ||
| + | delay(1000); | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | ++bootCount; | ||
| + | Serial.println(" | ||
| + | | ||
| + | | ||
| + | |||
| + | print_wakeup_reason(); | ||
| + | |||
| + | |||
| + | |||
| + | esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, | ||
| + | |||
| + | *//During Sleep only Pins connected to the RTC are operational | ||
| + | *//A General Purpose Input/ | ||
| + | *//By default those pins have no predefined purpose. | ||
| + | *//The pin used has to be named after their GPIO | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); | ||
| + | |||
| + | Serial.println(" | ||
| + | " Seconds" | ||
| + | |||
| + | |||
| + | Serial.println(" | ||
| + | delay(1000); | ||
| + | Serial.flush(); | ||
| + | | ||
| + | esp_deep_sleep_start(); | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | *** There is no loop section in our coding because the micro controller will go into deep sleep before reaching that part// | ||
| + | of the code, which means everything has to be written in the void set up section of the sketch.// | ||
| + | |||
| ====== | ====== | ||
| + | {{ : | ||
| + | |||
| + | |||
| + | |||
| + | |||
amc2022/grouph/here.1660126420.txt.gz · Last modified: 2023/01/05 14:38 (external edit)