#wake_alarm not set when on battery
1 messages · Page 1 of 1 (latest)
Here's the code:
magtag.peripherals.deinit()
pause = alarm.time.TimeAlarm(
monotonic_time=time.monotonic() + 300
)
button = alarm.pin.PinAlarm(pin=board.D15, value=False, pull=True)
alarm.exit_and_deep_sleep_until_alarms(pause, button)
wake_alarm is also None when the TimeAlarm wakes the device
CP 7.0.0 rc1
Does the time alarm work at all if you don't press the button on that first cycle when only on battery?
Ah ok, I've been able to reproduce your issue, I'm going to post a little extra code to help identify the behavior, then I'll do a bit of poking about. I need to read through the docs to see if this is an expected behavior or an issue
import alarm
import board
import digitalio
import neopixel
import time
import microcontroller
from adafruit_magtag.magtag import MagTag
print("Hello World!")
magtag = MagTag()
magtag.add_text(
text_scale=2,
text_wrap=25,
text_maxlen=300,
text_position=(10, 10),
text_anchor_point=(0, 0),
)
pause = alarm.time.TimeAlarm(
monotonic_time=time.monotonic() + 60
)
magtag.set_text(
"battery: {}V Pin: {} Timer: {}".format(
magtag.peripherals.battery, str(isinstance(alarm.wake_alarm, alarm.pin.PinAlarm)),
str(isinstance(alarm.wake_alarm, alarm.time.TimeAlarm))
)
)
magtag.peripherals.deinit()
# pause = alarm.time.TimeAlarm(
# monotonic_time=time.monotonic() + 60
# )
print("Sleeping in 5")
time.sleep(5)
print("sleeping..")
magtag.refresh()
button = alarm.pin.PinAlarm(pin=board.D15, value=False, pull=True)
alarm.exit_and_deep_sleep_until_alarms(pause, button)```
I've adjusted the code to make the debugging step to validate the issue more clear--effectively it just prints what the alarm was to the eink screen and shows the battery voltage that way it's easier to notice an update has occurred, without needing to play with the deep sleep memory settings
@languid citrus I think this is a bug you've found: This learn guide implies the isinstance should show the wake alarm type even though the wake alarm values might not be correct. https://learn.adafruit.com/deep-sleep-with-circuitpython/alarms-and-sleep
I tested the scenario and when faking deep sleep while plugged in, the screen showed the correct alarm was being trigger, but when unplugged after 1 cycle of wake alarms it would always say the type comparison was false regardless of why it woke up. (the 1 cycle was needed as it was still faking deep sleep so after that 1 cycle of an alarm it would still maintain memory of why it woke up.)
So, if you'd like, this probably should be filed as an issue over on github: https://github.com/adafruit/circuitpython/issues
I can help walk you through the process if you're new to it, otherwise go for it! Thanks for digging, and getting a minimal example working!
Thanks for validating @brave flame - I will file an issue
Fantastic! I'll keep an eye out for it, while I'm not familiar with the lower level deep sleep stuff, I might be able to at least help test solutions which should help us validate a solution. Thanks for being up for opening an issue and for bring this up!
I might see if I can work around the issue using sleep_memory
What are you trying to achieve? There's a few ways you could work around it--if you check a stored, "I went to sleep" time, you might be able to compare it to the current clock time and see if it's within some range of the timer alarm (maybe just py if current time.monotonic - go_to_sleep_monotonic > sleep duration: alarm_type = 'timer' else: alarm_type = 'button' would be sufficient?)
Regardless, as far as I can tell your core issue is a bug and once that's fixed you won't need a work around
do you have a github username? I will credit you in the bug report if so
KeithTheEE
Fantastic, thank you for the bug report! That's fantastic! Hopefully it'll be sorted out quickly. Would the above bodge solution be a possible work around until then?
it's a good idea but I don't think it will work for me. I want to be really sure the button was pressed
Aw bummer. I'll have to toy around with this and read a bit more into the source code and see if I can't find a workaround in the meantime. Regardless, I'm off for the night, thank you for noticing this and making the bug report!