[solved] rtc.alarm0 and timer do not work at the same time to get up from deepsleep

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
vanous
Posts: 4
Joined: Fri Mar 31, 2017 10:07 am

[solved] rtc.alarm0 and timer do not work at the same time to get up from deepsleep

Post by vanous » Fri Mar 31, 2017 10:48 am

edit: solved by using daily builds, esp8266-20170409-v1.8.7-602-gb87432b.bin

Hi,

i have tried searching on the interwebs and on the forum but no luck. New account, no bbcode yet.

When i try to use timer and rtc.irq with rtc.alarm0 at the same time, the board is never woken up. If instead of timer i use time.sleep, all is ok. Is this some limitation of the timer? The docs say it is "executing in an interrupt context"

The idea is to run timer and have it to trigger deepsleep. The main reason i do this is to have some sleep time to be able to remotely get to the board and update the software. I tried different combinations of times, but to no avail. DTR - XPD are connected and deepsleep wake up actually works if no timer is used.

This doesn't work, board never wakes up:

..init, connect to wifi...

rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, 1000*10)

tim = Timer(-1)
tim.init(period=8000, mode=Timer.ONE_SHOT, callback=lambda t:machine.deepsleep())


This code below works as expected (full proof of concept code)

import webrepl
import network
import machine
webrepl.start()

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ESSID', 'keep_looking')
import time
time.sleep(5) #wait for connection to be ready

import fan
fan.run() #do some networking stuff here, not related. uses import urequests

time.sleep(20) # do not go to deepsleep right away, to be able to connect and change the script at some time later :)
#todo: add check if this is hard reset and do not waste battery on deepsleep wake ups

rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, 1000*10)
machine.deepsleep()

Any idea what is going on? MP esp8266-20170108-v1.8.7.bin on ESP-01 ESP8266, DTR - XPD connected.
Thank you
Last edited by vanous on Sun Apr 09, 2017 2:55 pm, edited 1 time in total.

User avatar
vanous
Posts: 4
Joined: Fri Mar 31, 2017 10:07 am

Re: rtc.alarm0 and timer do not work at the same time to get up from deepsleep

Post by vanous » Sun Apr 09, 2017 2:54 pm

For anyone interested, using daily builds (esp8266-20170409-v1.8.7-602-gb87432b.bin) solved the issue.

Post Reply