User Tools

Site Tools


amc2020:group_n:deepsleep

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amc2020:group_n:deepsleep [2020/07/27 17:21] jonas001amc2020:group_n:deepsleep [2021/08/24 17:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<html>
 +  <left>
 +    <a href="https://wiki.eolab.de/doku.php?id=amc2020:group_n:start"; onmouseover="style.color='green'";>
 +      <span style="color:#2E71B8"; onmouseover="style.color='green'"; onmouseout="style.color='#2E71B8'";>
 +        &#8617 Back to the main page
 +      </span>
 +    </a>
 +  </left>
 +</html>
 +
 ====== ESP32 Deep Sleep Mode ====== ====== ESP32 Deep Sleep Mode ======
  
Line 71: Line 81:
 ==== 3.2 The Code Explained ==== ==== 3.2 The Code Explained ====
  
 +<html>
 +    <ol>
 +        <li>
 +            After including the <b><font face="Courier New"><font style="color:#CD5307">Wire</font>.h</font> </b> library for I2C communication and defining the DS3231 I2C address as <b><font face="Courier New">0x68</font></b>, the I2C pins of the ESP32 need to be defined. By default SCL is GPIO 22 and SDA is GPIO 21, but it is possible to use almost all pins for I2C communication if done correctly. Here just the default pins are used.
 +        </li>
 +        <li>
 +            The function <b><font face="Courier New">clearAlarm1()</font></b> is the only one, that must be copied into the new sketch.
 +        </li>
 +        <br>
 +        <li>
 +            When using the <b><font face="Courier New"><font style="color:#CD5307">Wire</font>.<font style="color:#CD5307">begin</font>()</font></b> method to start the I2C bus, the I2C pins previously defined need to be given as argument.
 +        </li>
 +        <li>
 +            After waking up, the alarm flag 1 of the DS3231's status register needs to be reset, otherwise the interrupt is fired continuously and the ESP32 would immediately wake up again after going into sleep mode. Therefore, <b><font face="Courier New">clearAlarm1()</font></b> is used to reset the alarm in the beginning.
 +        </li>
 +        <li>
 +            The serial connection is started to test whether the sketch is working. After waking up, the ESP32 prints some data to the monitor. Then a counter is counting down from 3 to 0 and the ESP32 goes back into deep sleep.
 +        </li>
 +        <li>
 +            The function <b><font face="Courier New">esp_sleep_enable_ext0_wakeup()</font></b> defines the method for waking the ESP32 up from deep sleep. The <b><font face="Courier New">ext0</font></b> means that the the wake up source is external and can only be triggered by a single pin. The number of the pin is given in the argument as <b><font face="Courier New">GPIO_NUM_X</font></b> where X represents the GPIO number of that pin. The second argument (level) defines which state the pin needs to be in to wake the ESP32 up. A <b><font face="Courier New">1</font></b> means that it will wake up, when the voltage is 3.3V. A <b><font face="Courier New">0</font></b> means it wakes up when it is 0V. As the DS3231 pulls the pin to GND when the alarm is activated, the level needs to be <b><font face="Courier New">0</font></b>.
 +        </li>
 +        <li>
 +            The function <b><font face="Courier New">esp_deep_sleep_start()</font></b> changes the power mode of the ESP32 to deep sleep.
 +        </li>
 +        <li>
 +            When the deep sleep is activated, the rest of the program code is just not executed. After resetting, the ESP32 starts again with the <b><font face="Courier New"><font style="color:#5A6B0F">setup</font>()</font></b>. Therefore, this line should never be printed to the serial monitor; otherwise there is an error. The program also never reaches the main <b><font face="Courier New"><font style="color:#5A6B0F">loop</font>()</font></b>.
 +        </li>
 +    </ol>
 +</html>
 +
 +==== 3.3 Results ====
 +
 +Apart from the timestamps on the left, the result in the serial monitor should look like this. In the data that the ESP32 prints by itself, it can be seen that the reset occured due to waking up from deep sleep (1). Furthermore, the last serial print command was not executed because deep sleep was activated before that could happen.
 +
 +When comparing the time stamps (1, 3 and 4) it becomes visible that the wake up from deep sleep occurred always 1 minute after the last wake up. However, the milliseconds are always varying a little bit. This might be due to the temperature compensation of the DS3231 through which the capacitance and therefore the frequency of the oscillator are changed. So, there might be very small inaccuracies, but they are constantly compensated for by the module, such that the total drift stays very low.
 +
 +<code>
 +18:50:42.643 -> ets Jun  8 2016 00:22:57
 +18:50:42.643 -> 
 +18:50:42.643 -> rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) //1
 +18:50:42.643 -> configsip: 0, SPIWP:0xee
 +18:50:42.643 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
 +18:50:42.643 -> mode:DIO, clock div:1
 +18:50:42.643 -> load:0x3fff0018,len:4
 +18:50:42.643 -> load:0x3fff001c,len:1216
 +18:50:42.643 -> ho 0 tail 12 room 4
 +18:50:42.643 -> load:0x40078000,len:10864
 +18:50:42.643 -> load:0x40080400,len:6432
 +18:50:42.643 -> entry 0x400806b8
 +18:50:43.793 -> ESP32 woke up from deep sleep.
 +18:50:43.793 -> Going back to sleep in 3
 +18:50:44.783 -> Going back to sleep in 2
 +18:50:45.743 -> Going back to sleep in 1
 +18:50:46.743 -> Going back to sleep in 0                                  //2
 +18:51:42.633 -> ets Jun  8 2016 00:22:57                                  //3
 +18:51:42.633 -> 
 +18:51:42.633 -> rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
 +18:51:42.633 -> configsip: 0, SPIWP:0xee
 +18:51:42.633 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
 +18:51:42.633 -> mode:DIO, clock div:1
 +18:51:42.633 -> load:0x3fff0018,len:4
 +18:51:42.633 -> load:0x3fff001c,len:1216
 +18:51:42.633 -> ho 0 tail 12 room 4
 +18:51:42.633 -> load:0x40078000,len:10864
 +18:51:42.633 -> load:0x40080400,len:6432
 +18:51:42.633 -> entry 0x400806b8
 +18:51:43.782 -> ESP32 woke up from deep sleep.
 +18:51:43.782 -> Going back to sleep in 3
 +18:51:44.763 -> Going back to sleep in 2
 +18:51:45.753 -> Going back to sleep in 1
 +18:51:46.763 -> Going back to sleep in 0
 +18:52:42.653 -> ets Jun  8 2016 00:22:57                                  //4
 +18:52:42.653 -> 
 +18:52:42.653 -> rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
 +18:52:42.653 -> configsip: 0, SPIWP:0xee
 +18:52:42.653 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
 +18:52:42.653 -> mode:DIO, clock div:1
 +18:52:42.653 -> load:0x3fff0018,len:4
 +18:52:42.653 -> load:0x3fff001c,len:1216
 +18:52:42.653 -> ho 0 tail 12 room 4
 +18:52:42.653 -> load:0x40078000,len:10864
 +18:52:42.653 -> load:0x40080400,len:6432
 +18:52:42.653 -> entry 0x400806b8
 +18:52:43.753 -> ESP32 woke up from deep sleep.
 +18:52:43.753 -> Going back to sleep in 3
 +18:52:44.753 -> Going back to sleep in 2
 +18:52:45.793 -> Going back to sleep in 1
 +18:52:46.783 -> Going back to sleep in 0
 +</code>
 +
 +<html>
 +  <center>
 +    <span>
 +    <a href="javascript:self.scrollTo(0,0)"; onmouseover="style.color='green'";>
 +      <span style="color:#2E71B8"; onmouseover="style.color='green'"; onmouseout="style.color='#2E71B8'";>
 +        Back to the top &#10548
 +      </span>
 +    </a>
 +    </span>
 +  </center>
 +</html>
amc2020/group_n/deepsleep.1595863318.txt.gz · Last modified: 2021/08/24 17:34 (external edit)