![]() ![]() 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. 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. ![]() ![]() If you put your ESP8266 in deep sleep mode, it reduces power consumption and your batteries will last longer. After running it for a while, you realize the battery doesn’t last long, specially if you’re using Wi-Fi. If you’ve made a project with an ESP8266 board that is battery powered, or if you just connected your ESP8266 NodeMCU board to a power bank. Related Content: ESP32 Deep Sleep with Arduino IDE and Wake Up Sources Introducing Deep Sleep Mode This guide is available in video format (watch below) and in written format (continue reading this page). The ESP8266 will wake up when the RST pin receives a LOW signal. To put the ESP8266 in deep sleep mode for an indefinite period of time use ESP.deepSleep(0). GPIO 16 must be connected to reset (RST) pin so the ESP8266 is able to wake up. To put the ESP8266 in deep sleep mode, use ESP.deepSleep(uS) and pass as argument sleep time in microseconds. We’ll cover deep sleep with timer wake up and deep sleep with external wake up using the reset (RST) pin. It blinks the on-board LED and goes back to sleep.This guide shows how to use deep sleep with the ESP8266 (NodeMCU) using Arduino IDE. Every time you press the pushbutton that is connected to the RST pin, the ESP8266 resets and wakes up. DemonstrationĪfter wiring the circuit and uploading the code, you can test your setup. When you call epsleep() without any arguments, the ESP8266 will go into deep sleep mode indefinitely until you press the RST button. In this case, you just need to call epsleep() after the execution of the main code. Upload the following code to the ESP8266 as main.py. If you don’t know how to upload the script follow this tutorial if you’re using Thonny IDE, or this one if you’re using uP圜raft IDE.Īfter uploading the code, you need to connect GPIO16 (D0) to the RST pin so that the ESP8266 can wake itself up. Uploading the CodeĬopy the code provided to the main.py file and upload it to your ESP8266. deep_sleep(10000)Īfter 10 seconds, the ESP8266 wakes up and runs the code from the start, similarly of when you press the RESET button. After having the final code, you can remove that delay.įinally, put the ESP8266 in deep sleep for 10 seconds (10 000 milliseconds) by calling the deep_sleep() function and passing as argument the number of milliseconds. So, if you don’t have the delay, it will be difficult to catch it awake to upload code later on. When you want to upload a new code to your board, it needs to be awaken. It’s important to add that delay of 5 seconds before going to sleep when we are developing the script. led.value(1)īefore going to sleep, we add a delay of 5 seconds and print a message to indicate it is going to sleep. led = Pin(2, Pin.OUT)Īfter that, add the deep_sleep() function to your code: def deep_sleep(msecs): For our board, it refers to the on-board LED. #sleep for 10 seconds (10000 milliseconds)įirst, import the necessary libraries: import machineĬreate a Pin object that refers to GPIO 2 called led. ![]() # you should remove this sleep line in your final script # wait 5 seconds so that you can catch the ESP awake to establish a serial communication later # set RTC.ALARM0 to fire after X milliseconds (waking the device) # configure RTC.ALARM0 to be able to wake the device This process is repeated over and over again. When it wakes up, it blinks an LED, and goes back to sleep again. In the following code, the ESP8266 is in deep sleep mode for 10 seconds. To use this function later in your code, you just need to pass as an argument the sleep time in milliseconds. This deep_sleep() function creates a timer that wakes up the ESP8266 after a predetermined number of seconds. We recommend copying the previous function to the beginning of your script, and then call the deep_sleep() function to put the ESP8266 in deep sleep mode. # set RTC.ALARM0 to fire after Xmilliseconds, waking the device Rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP) #configure RTC.ALARM0 to be able to wake the device One of the easiest ways is using the following function in your code. There are slightly different ways to wake up the ESP8266 with a timer after deep sleep. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |