# SWAN R5: Sleep modes in CircuitPython are broken

**URL:** https://discuss.blues.com/t/swan-r5-sleep-modes-in-circuitpython-are-broken/1983
**Category:** Tools & SDKs
**Created:** [February 24, 2024, 8:19am UTC](https://discuss.blues.com/t/swan-r5-sleep-modes-in-circuitpython-are-broken/1983 "2024-02-24T08:19:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![datalogger](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@datalogger](https://discuss.blues.com/u/datalogger)
#### Post date: [February 24, 2024, 8:19am UTC](https://discuss.blues.com/t/swan-r5-sleep-modes-in-circuitpython-are-broken/1983/1 "2024-02-24T08:19:26Z")

</div>

Hi,

light and deep-sleep modes in CircuitPython are broken for the SWAN R5. Light-sleep uses almost twice as much current than a “normal” `time.sleep()`. Deep-sleep does not work at all, the device wakes up right after entering that low-power state.

I opened an issue with CircuitPython for that:

> <https://github.com/adafruit/circuitpython/issues/8977>
>
> \### CircuitPython version
> 
> \`\`\`python
> Adafruit CircuitPython 8.2.9 on 2023-12-06;… Swan R5 with STM32L4R5ZIY6
> \`\`\`
> 
> 
> \### Code/REPL
> 
> \`\`\`python
> def work():
> led.value = 1
> time.sleep(LED\_TIME)
> led.value = 0
> 
> while True:
> # do some work
> work()
> 
> # sleep
> if MODE == SPIN:
> next = time.monotonic() + INT\_TIME
> while time.monotonic() \< next:
> continue
> elif MODE == SLEEP:
> print(f"(normal) sleep for {INT\_TIME}s")
> time.sleep(INT\_TIME)
> elif MODE == LIGHT\_SLEEP:
> print(f"(light) sleep for {INT\_TIME}s")
> time\_alarm = alarm.time.TimeAlarm(monotonic\_time=time.monotonic()+INT\_TIME)
> alarm.light\_sleep\_until\_alarms(time\_alarm)
> elif MODE == DEEP\_SLEEP:
> print(f"(deep) sleep for {INT\_TIME}s")
> time\_alarm = alarm.time.TimeAlarm(monotonic\_time=time.monotonic()+INT\_TIME)
> alarm.exit\_and\_deep\_sleep\_until\_alarms(time\_alarm)
> \`\`\`
> 
> 
> \### Behavior
> 
> With light-sleep, I can see the following current (at 3.6V):
> !\[swan-timer-light-sleep\](https://github.com/adafruit/circuitpython/assets/9638355/c52a76de-ae2c-4e3f-b81b-2c48f62b6857)
> 
> So in light-sleep mode, the SWAN needs about 30mA. When the LED is on and the device sleeps normally (during \`work()\`), current is only about 16mA.
> 
> Deep-sleep is even more broken:
> !\[swan-timer-deep-sleep\](https://github.com/adafruit/circuitpython/assets/9638355/94460d91-6720-4d84-a0da-98d0be4b43e4)
> 
> You can see that the device tries to switch to deep-sleep, but it wakes up again without actually sleeping (note that this is not fake deep-sleep, there was no USB connection). After wake up, you can see the 16mA during \`work()\` again, then the try-to-go-to-deep-sleep-and-fail cycle starts over.
> 
> \### Description
> 
> \_No response\_
> 
> \### Additional information
> 
> \_No response\_

---

<div class="post-metadata">

### Author: ![RobLauer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/roblauer/32/1567_2.png) [@RobLauer](https://discuss.blues.com/u/RobLauer)
#### Post date: [February 27, 2024, 5:01pm UTC](https://discuss.blues.com/t/swan-r5-sleep-modes-in-circuitpython-are-broken/1983/2 "2024-02-27T17:01:16Z")

</div>

Hi @datalogger,

Thanks for logging the issue on the CircuitPython repo. We are also investigating this internally.

Rob
