#1 timer wake up: the ESP8266 wakes itself up after a predefined period of time.The process is repeated over and over againĪfter putting the ESP8266 in deep sleep mode, there are different ways to wake it up:.The ESP8266 performs a task (reads a sensor, publishes an MQTT message, etc).With deep sleep, an example application looks like this: However, if you use a full-feature development board with built-in programmer, LEDs, and so on, you won’t be able to achieve such a low power state. This is the most power efficient option and the ESP chip only draws approximately 20uA. Everything is always off, except the Real Time Clock (RTC), which is how the ESP8266 keeps track of time. In this article, we’ll cover deep sleep mode. They all have different purposes and they should be used in different applications. If you’re using a development board, they have passive components that use more current. Note: the power consumption on the table refers to the ESP8266 as a standalone chip. The table below shows the differences between each mode (information from the ESP8266 datasheet). There are three different types of sleep mode: modem sleep, light sleep, and deep sleep. Having the ESP8266 in deep sleep mode means cutting with the activities that consume more power while operating (like Wi-Fi) but leave just enough activity to wake up the processor when something interesting happens. This permits very long idle periods (hours, days, or weeks possible) so long as you have a reliable method of waking the device up by triggering the RESET pin.If you put your ESP8266 in deep sleep mode, it reduces power consumption and your batteries will last longer. Or, rather, use a value of zero to specify that the ESP should sleep forever (until reset, that is): node.dsleep(0) In this case, you don’t need to connect GPIO16 to the RESET pin, and you don’t need to specify an alarm value when calling dsleep(). So, instead of using the internal RTC, your device may have an external RTC, or a button that the user must press, or some other mechanism that runs while the ESP8266 is asleep, and then triggers a device reset in much the same way (by transitioning the RESET pin from high to low). You must be aware of the underlying SDK that the firmware is based on, because that impacts the maximum deep sleep timer value that can be used.Īnother use of deep sleep is to sleep until externally triggered. Note: As of the time of this writing, the Master branch of the NodeMCU Firmware project in GitHub is based on SDK 1.4, while the Dev branch is based on 1.5.1. If it reaches a certain threshold, then do the work, otherwise go back to sleep. One common way to extend this is to maintain a counter in NVM (i.e., Flash or RTC Memory), and increment the counter each time that the device wakes up. Earlier SDK versions had a lower limit, closer to 35 minutes. With the current 1.5.1 SDK, the maximum value accepted is 4,294,967,295, which is about 71 minutes. The dsleep() function accepts microseconds as its parameter (1,000,000 microseconds = 1 second), and the multiplication performed inline here is just to make it clearer that we’re sleeping for 15 minutes total. Your start up scripts should go through the motions of connecting to Wi-Fi, collecting sample data (or whatever work the device is to do), and then when it comes time to sleep, execute the following: node.dsleep(15 * 60 * 1000000) The RESET pin is triggered by a low logic signal, so when the RTC’s alarm fires, it will transition GPIO16 from high to low in order to perform the reset (i.e., wake the device up).įinally, you need code to actually put the device to sleep. GPIO16 belongs to the RTC module on the silicon, so that’s the only GPIO that the RTC can control directly while in low-power mode. The first thing is that you need to connect GPIO16 to the RESET pin using a small resistor (i.e., 300–1k - see Rudy’s description in the comments). This may sound like a complicated orchestration, but fortunately, the SDK provides an abstraction layer over this functionality so that you only need to call a function (and NodeMCU provides a Lua wrapper around this SDK functionality). At a certain time, an alarm in the RTC changes the state of a GPIO pin in order to trigger a device reset, which has the effect of waking the device up (albeit, from a full reset instead of resuming from where it left off). While in deep sleep mode, the processor stops and the RAM is powered down (saving precious battery life), but the RTC continues to function. But, how would you force an ESP8266 to go to sleep, but wake up when it needs to? The solution is to combine the low-power state of the ESP8266 with the internal Real-Time Clock (RTC) and the device’s Reset pin.
0 Comments
Leave a Reply. |