amc2022:grouph:here
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| amc2022:grouph:here [2022/08/30 19:03] – 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/ | ||
| - | ====== | ||
| + | ====== | ||
| - | <html> | + | <code c++> |
| - | < | + | |
| - | <font color="# | + | |
| - | <font color="# | + | |
| - | <font color="# | + | *//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; | ||
| - | <font color="# | + | *//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. |
| + | *//Therefore we decided to just Keeping data of times awaken in internal RTC, this will help us see if any issues occur. | ||
| - | & | ||
| - | & | ||
| - | & | ||
| - | & | ||
| - | & | ||
| - | & | ||
| - | <font color="# | ||
| - | <font color="# | ||
| - | & | ||
| - | & | ||
| - | & | + | **************Wake Up Print ************************************************************** |
| - | & | + | void print_wakeup_reason(){ *//Set up to list reasons for system wake-up |
| + | esp_sleep_wakeup_cause_t wakeup_reason; | ||
| - | & | + | wakeup_reason |
| - | <font color="# | + | |
| - | & | + | |
| - | & | + | |
| - | & | + | |
| - | & | + | |
| - | & | + | |
| + | 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, | |
| - | <font color="# | + | *// 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); | ||
| + | | ||
| + | |||
| + | pinMode(32, | ||
| + | |||
| + | pinMode(33, | ||
| + | |||
| + | *//ESP32 has pull-up resistors built on the pins, when we activate it | ||
| + | *//it avoids the use of external resistors | ||
| + | *//INPUT_PULLUP keeps the signal HIGH by default | ||
| + | *//floating currents which can produce erroneous readings are avoided by pull up/down resistors | ||
| + | |||
| + | |||
| + | |||
| + | for(int i=0;i<5; | ||
| + | { | ||
| + | digitalWrite(32, | ||
| + | delay(1000); | ||
| + | digitalWrite(32, | ||
| + | delay(1000); | ||
| + | } | ||
| - | & | ||
| - | & | ||
| - | & | ||
| - | & | + | ++bootCount; |
| + | Serial.println("Reboot count number: | ||
| + | *//easy way to know if there are issues internal or battery | ||
| + | | ||
| + | |||
| + | 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); *//conversion factor to minutes | ||
| - | & | + | |
| - | & | + | " Seconds" |
| + | |||
| + | |||
| + | Serial.println("Going to sleep now......"); | ||
| + | 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.1661879011.txt.gz · Last modified: 2023/01/05 14:38 (external edit)