You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code randomly does not invoke Magtag.exit_and_deep_sleep() #10639
Normally, when the code finishes, the console writes:
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
Pretending to deep sleep until alarm, CTRL-C or file write.
Woken up by alarm.
However, after several hours, you see:
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
and the board is frozen, without invoking deep sleep.
This seems like it might be due to the host computer you are connected to going to sleep while "fake deep sleep" is happening. Is it true that host computer goes to sleep during the several hours you mentioned?
@dhalbert : Thanks. I can reproduce this when the Magtag is disconnected from the computer. I just posted the console log for illustration.
I am testing a much simpler version below. The board is currently disconnected from the computer. Will post an update in a few hours when I have tested it more.
from adafruit_magtag.magtag import MagTag
from os import getenv
import terminalio
url = getenv("PWD_URL")
print("Getting data from URL "+url)
magtag = MagTag(
url=url,
json_path=[['timestamp']]
)
magtag.add_text(
text_font=terminalio.FONT,
text_position=(20,20),
)
try:
magtag.fetch()
except Exception as e:
print("Exception: "+str(e))
sleepTime = 10
print("Entering deep sleep for "+str(sleepTime)+" sec")
magtag.exit_and_deep_sleep(sleepTime)
Thanks but there is a try-except block in my main code already. (There wasn't in my attempt at a minimally reproducible sample - just fixed that above).
Here is a minimum reproducible example that fails to update after a few hours when the Magtag is plugged into a USB power supply, not a computer. Also, note that I have two Magtags and I can reproduce this failure on both boards, which suggests this is a software issue, not a hardware issue.
from adafruit_magtag.magtag import MagTag
import terminalio
import random
sleepTime = random.randint(1,30)
magtag = MagTag()
magtag.add_text(
text_font=terminalio.FONT,
text_position=(20,20),
text="Sleeping for "+str(sleepTime)+" sec"
)
magtag.exit_and_deep_sleep(sleepTime)
When you say "a few hours", is that time actually consistent?
I modified the test so that it is deterministic. See below. I confirmed the number of iterations is not consistent: I got failures with 61 and 16 trials, on the same MagTag. To reset the counter, run the two commented lines via REPL.
from adafruit_magtag.magtag import MagTag
import terminalio
import microcontroller
## INIT NVM via REPL
# i = 0
# microcontroller.nvm[0:8] = i.to_bytes(8)
i = 1+int.from_bytes(microcontroller.nvm[0:8])
magtag = MagTag()
magtag.add_text(
text_font=terminalio.FONT,
text_position=(20,20),
text="Trial "+str(i)
)
microcontroller.nvm[0:8] = i.to_bytes(8)
magtag.exit_and_deep_sleep(2)
@dhalbert: I am not sure what you mean here. Do you mean waiting for some "sufficient" time interval?
@bablokb: Exactly: don't pass a busy_pin to make display.busy wait.
@bablokb if, as you say, the option is only to wait, do you mean that for each display type we need to know how long it takes to finish its operations? Or that the CircuitPython e-ink display code can know when to stop waiting in general? Thanks.
That is also my solution. For the displays with a reliable busy-pin, I just wait on the pin. This also works with a 74HC165D. For other displays, I measure the typical time needed and just hardcode the wait-time.
I don't think that deep-sleep should do that. This is the type of commodity thing that solves some problems while creating new ones. From Python-side, two lines are sufficient.
It is a common use case to update the e-Ink display immediately before putting the device into deep sleep. However, I believe that the status quo is deficient: I had to spend several days debugging what appeared as a random failure. Therefore I urge you to implement one of the following:
Treat this as a code defect and update the CircuitPython libraries to delay deep sleep while board.DISPLAY.busy is true
Treat this as a documentation issue that:
a. Clearly documents that an update to the display may cause deep sleep to fail
b. Includes a simple example showing a while loop that waits for board.DISPLAY.busy to be false before calling adafruit_magtag.magtag.MagTag.exit_and_deep_sleep()
Activity
dhalbert commentedon Sep 22, 2025
This seems like it might be due to the host computer you are connected to going to sleep while "fake deep sleep" is happening. Is it true that host computer goes to sleep during the several hours you mentioned?
gglockner commentedon Sep 22, 2025
@dhalbert : Thanks. I can reproduce this when the Magtag is disconnected from the computer. I just posted the console log for illustration.
I am testing a much simpler version below. The board is currently disconnected from the computer. Will post an update in a few hours when I have tested it more.
dhalbert commentedon Sep 22, 2025
If the
magtag.fetch()fails, I think you will get an (uncaught) exception. So you could catch all exceptions and try again or just go to sleep.gglockner commentedon Sep 22, 2025
Thanks but there is a try-except block in my main code already. (There wasn't in my attempt at a minimally reproducible sample - just fixed that above).
gglockner commentedon Sep 22, 2025
I can confirm that it fails with the simpler code above, even with the Magtag disconnected from a computer.
gglockner commentedon Sep 22, 2025
Here is a minimum reproducible example that fails to update after a few hours when the Magtag is plugged into a USB power supply, not a computer. Also, note that I have two Magtags and I can reproduce this failure on both boards, which suggests this is a software issue, not a hardware issue.
dhalbert commentedon Sep 22, 2025
OK, so not even a fetch is involved. When you say "a few hours", is that time actually consistent?
dhalbert commentedon Sep 22, 2025
Could you try 9.2.9 as well? Thanks. It would be useful to know if this is a regression.
gglockner commentedon Sep 22, 2025
I don't know. It takes too long to babysit.
Unfortunately no, according to the instructions for installing CircuitPython:
So I cannot run CircuitPython 9.2.9 for my MagTag 2025 Edition.
dhalbert commentedon Sep 22, 2025
Thanks anyway, I have an older MagTag and can test.
gglockner commentedon Sep 22, 2025
I modified the test so that it is deterministic. See below. I confirmed the number of iterations is not consistent: I got failures with 61 and 16 trials, on the same MagTag. To reset the counter, run the two commented lines via REPL.
16 remaining items
dhalbert commentedon Jul 24, 2026
@gglockner @bablokb I am looking at this again.
@bablokb I get the idea from the above that adafruit/Adafruit_CircuitPython_MagTag#96 is sufficent for the MagTag display but not in general. So perhaps I should merge that library PR. @gglockner do you have any new opinions on this.
@bablokb if, as you say, the option is only to wait, do you mean that for each display type we need to know how long it takes to finish its operations? Or that the CircuitPython e-ink display code can know when to stop waiting in general? Thanks.
gglockner commentedon Jul 24, 2026
Thanks @dhalbert, I have nothing new to add. In my own project, I simply implemented a workaround to loop while
board.DISPLAY.busyis true.bablokb commentedon Jul 24, 2026
That is also my solution. For the displays with a reliable busy-pin, I just wait on the pin. This also works with a 74HC165D. For other displays, I measure the typical time needed and just hardcode the wait-time.
I don't think that deep-sleep should do that. This is the type of commodity thing that solves some problems while creating new ones. From Python-side, two lines are sufficient.
gglockner commentedon Jul 24, 2026
It is a common use case to update the e-Ink display immediately before putting the device into deep sleep. However, I believe that the status quo is deficient: I had to spend several days debugging what appeared as a random failure. Therefore I urge you to implement one of the following:
board.DISPLAY.busyis truea. Clearly documents that an update to the display may cause deep sleep to fail
b. Includes a simple example showing a while loop that waits for
board.DISPLAY.busyto be false before callingadafruit_magtag.magtag.MagTag.exit_and_deep_sleep()Thanks.
epaperdisplay: don't let background finish a refresh being released