sleep and deepsleep

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
pmr1
Posts: 3
Joined: Tue Nov 03, 2015 9:01 am

sleep and deepsleep

Post by pmr1 » Sun Nov 29, 2015 2:10 pm

I have trouble getting a wipy to repeated go to sleep after executing some housekeeping and eventually reading some sensor. However the code below sleeps only once. I am using MicroPython v1.5-1-ge954604 on 2015-10-21; WiPy with CC3200

# code begin
import machine
from machine import RTC
import wipy

rtc = machine.RTC() # init with default time and date
rtc = RTC(datetime=(2015, 10, 31, 18, 0, 0, 0, None)) # init with a specific time and date
# print(rtc.now())
wipy.heartbeat(False) # disable the heartbeat LED

def alarm_handler (rtc_o):
wipy.heartbeat(False) # disable the heartbeat LED
machine.sleep()
# do some non blocking operations
# warning printing on an irq via telnet is not
# possible, only via UART

# create a RTC alarm that expires after 10 seconds
rtc.alarm(time=10000, repeat=True) # expected this to repeatedly set the alarm

# enable RTC interrupts
rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.DEEPSLEEP)


# I can't get this to go into repeated sleep !!! kinda expected in repeat set true above that the instructions would execute in the handler
while True:
wipy.heartbeat(False) # disable the heartbeat LED and keep current low
machine.deepsleep()


#code end

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: sleep and deepsleep

Post by dhylands » Sun Nov 29, 2015 5:06 pm

You should put your code inside [ code] Put code here [ /code] tags (remove the space after the opening square bracket.

Then your code retains its indentation, like this:

Code: Select all

while True:
    pass

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: sleep and deepsleep

Post by danicampora » Sun Nov 29, 2015 5:08 pm

Is it going to sleep once, waking up, going to sleep again and never waking up? If that's the case, there's a known issue with repeating RTC alarms and machine.sleep(). Please try to use single shot alarms instead (setup the alarm again after waking up).

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: sleep and deepsleep

Post by danicampora » Sun Nov 29, 2015 5:10 pm

Also, waking up from deepsleep works like coming out out of reset, so execution will being from main. You need to check the reset reason and decide what to do.

pmr1
Posts: 3
Joined: Tue Nov 03, 2015 9:01 am

Re: sleep and deepsleep

Post by pmr1 » Tue Dec 01, 2015 8:56 pm

dhylands wrote:You should put your code inside [ code] Put code here [ /code] tags (remove the space after the opening square bracket.

Then your code retains its indentation, like this:

Code: Select all

while True:
    pass

Code: Select all

import machine
from machine import RTC
import wipy

rtc = machine.RTC() # init with default time and date
rtc = RTC(datetime=(2015, 10, 31, 18, 0, 0, 0, None)) # init with a specific time and date

wipy.heartbeat(False) # disable the heartbeat LED

def alarm_handler (rtc_o):
wipy.heartbeat(False) # disable the heartbeat LED
machine.sleep()


# create a RTC alarm that expires after 10 seconds
rtc.alarm(time=10000, repeat=True) # expected this to repeatedly set the alarm 

# enable RTC interrupts
rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.DEEPSLEEP)


# I can't get this to go into repeated sleep !!! kinda expected in repeat set true above that the instructions would execute in the handler
while True:
	wipy.heartbeat(False) # disable the heartbeat LED and keep current low
	machine.deepsleep()

[/quote]

Ok thanks

Post Reply