As for your code example, I modified it to replace the print statement with one which toggles an onboard LED: I have doubts about printing coexisting with the Pyboard power saving modes. I ran it with the Pyboard powered from USB firstly with Vbat disconnected, then with Vbat linked to 3V3. In both cases the LED toggled every 30 seconds.
Code: Select all
import pyb
import micropython
micropython.alloc_emergency_exception_buf(100)
ledy = pyb.LED(3)
rtc = pyb.RTC()
sleepInterval = 30000 # in ms
interrupt_RTC = 0 # RTC Wake Event
def callback_RTC(line):
global interrupt_RTC
interrupt_RTC = 1
def mainloop():
global interrupt_RTC
while True:
if(interrupt_RTC == 1):
interrupt_RTC = 0
ledy.toggle()
pyb.stop() # go to sleep until next wakeup
rtc.wakeup(sleepInterval,callback_RTC) # every sleepInterval wake
mainloop()