The main goal is to reproduce similar low-power timer and wake-up functionalities in Micropython. It provides direct access to hardware registers through memory-mapped I/O and is intended for bare-metal embedded development.
This project is inspired by and based on the powman library implementation available in the Raspberry Pi Pico SDK
The library directly accesses the RP2350 power management and timer registers via memory-mapped I/O. Official documentation can be found in the RP2350 datasheet, especially in Section 6.0 (Power Management Overview and Section 6.4 (Register Configuration)
It is designed to control low-power modes, timers, and wake-up alarms on Raspberry Pi Pico 2.
Here for tinygo library
- Micropython
- Raspberry Pi Pico 2
Important:
powmanGetWakeupReason()must be called beforepowmanInit(), because init writes to POWMAN registers that may affect wake-up state.
import deepsleep
reason = deepsleep.powmanGetWakeupReason()
if reason == 0:
print("fresh boot")
elif reason & deepsleep.WAKEUP_ALARM:
print("woke from timer")
elif reason & deepsleep.WAKEUP_GPIO0:
print("woke from GPIO")Set the absolute system time in milliseconds (must be > 0):
deepsleep.powmanInit(1704067200)Sleep for a fixed duration (milliseconds):
deepsleep.powmanOffForMs(10000) # sleep 10 secondsOr sleep until a GPIO goes HIGH:
deepsleep.powmanOffUntilGPIO(15) # wake on GP15 HIGHBoth functions never return — the chip reboots on wake-up.
import deepsleep
import time
def main():
reason = deepsleep.powmanGetWakeupReason() # before init!
if reason == 0:
print("fresh boot")
elif reason & deepsleep.WAKEUP_ALARM:
print("woke from timer alarm")
elif reason & (deepsleep.WAKEUP_GPIO0 | deepsleep.WAKEUP_GPIO1 |
deepsleep.WAKEUP_GPIO2 | deepsleep.WAKEUP_GPIO3):
print("woke from GPIO")
deepsleep.powmanInit(1704067200)
deepsleep.powmanOffForMs(5000)
main()In main.py there is a minimal example`.
Power consumption over one minute.
The consumption during low power mode
Powman directly accesses memory-mapped registers to control:
- System timer
- Alarm registers
- Power regulator
- Boot configuration
- Interrupt enable flags
The library uses mem32 internally to read and write hardware registers.
This is required for bare-metal development and is safe in this context.
Returns the reason for the last wake-up as a bitmask. Must be called before powmanInit().
| Constant | Value | Meaning |
|---|---|---|
0 |
0x00 |
Fresh boot / software reset |
WAKEUP_CHIP_RESET |
0x01 |
Chip-level reset |
WAKEUP_GPIO0 |
0x02 |
Wake from PWRUP0 (used by powmanOffUntilGPIO) |
WAKEUP_GPIO1 |
0x04 |
Wake from PWRUP1 |
WAKEUP_GPIO2 |
0x08 |
Wake from PWRUP2 |
WAKEUP_GPIO3 |
0x10 |
Wake from PWRUP3 |
WAKEUP_ALARM |
0x40 |
Wake from timer alarm |
The register is a bitmask: multiple bits can be set simultaneously. Use & to test individual sources.
Internally reads CHIP_RESET.HAD_SWCORE_PD (bit 25) to confirm a POWMAN sleep occurred, then reads LAST_SWCORE_PWRUP (offset 0xA0) for the source.
Initializes the POWMAN timer with an absolute timestamp in milliseconds (must be > 0).
Enters deep sleep and reboots after sleepingMs milliseconds. Never returns.
Enters deep sleep and reboots when the specified GPIO pin reaches the target level. gpio must be 0–49. Never returns.
| Parameter | Description |
|---|---|
gpio |
GPIO pin number (0–49) |
high |
True = wake on HIGH, False = wake on LOW |
Important: The GPIO must already be at the opposite level before calling this function. POWMAN requires a level transition to fire — if the GPIO is already at the wake level when sleep is entered, the chip will never wake.
highGPIO must be before sleep Wake trigger TrueLOW GPIO goes HIGH FalseHIGH GPIO goes LOW
- Timer-based deep sleep (
powmanOffForMs) - GPIO wake-up (
powmanOffUntilGPIO) - Wake-up reason detection (
powmanGetWakeupReason)
- Optimize power management by disabling unnecessary components
- Implement a sleep mode that does not reboot the system and preserves the values of variables like
machine.lightsleep()
- Only use in embedded/bare-metal environments.
- Incorrect register values may brick your device.
Tested primarily on:
- Raspberry Pi Pico 2

