Jump to content

NodeMCU Projects: Difference between revisions

Line 87:
</syntaxhighlight>
 
== Deep-sleep mode ==
 
*This shut down the ESP8266 and all its peripherals & also WiFi.
*But not including the real-time-clock, which is used to wake the chip.
*This drastically reduces current consumption and is a good way to make devices that can run for a while on a battery.
*You Must connect GPIO16 to the reset pin.
 
<syntaxhighlight lang="python">
import machine
 
# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
 
# check if the device woke from a deep sleep
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print('woke from a deep sleep')
 
# set RTC.ALARM0 to fire after 10 seconds (waking the device)
rtc.alarm(rtc.ALARM0, 10000)
 
# put the device to sleep
machine.deepsleep()
</syntaxhighlight>
 
= Analog Temperature Meter =
Cookies help us deliver our services. By using our services, you agree to our use of cookies.