![esp8266 firmware rtc esp8266 firmware rtc](https://odd-one-out.serek.eu/assets/images/esp8266-nodemcu-oled-display-spi-modules.png)
Upload the following code to the ESP8266 as main.py.
#ESP8266 FIRMWARE RTC HOW TO#
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
#ESP8266 FIRMWARE RTC SERIAL#
# 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.