Tutorial: Power Management (esp_pm), ULP Coprocessors & Zero-Touch Onboarding
Battery-powered handhelds (Cardputer ADV, T-Deck, Core2, StickC Plus2) and compact sensor nodes (NanoC6, XIAO) require coordinated power management across the CPU, display backlight, 2.4 GHz / Sub-GHz radios, and ultra-low-power coprocessors.
1. Dynamic Frequency Scaling & Tickless Light Sleep (hal.pm_*)
PylotOS enables CONFIG_PM_ENABLE=y and CONFIG_FREERTOS_USE_TICKLESS_IDLE=y across all boards:
import hal
# Drop CPU to 80 MHz idle (scaling to 240 MHz on load) + automatic tickless light sleep:
cfg = hal.pm_configure(max_mhz=240, min_mhz=80, light_sleep=True)
# Inspect active ESP-IDF power locks (e.g. SPI/RMT TX locks held briefly by C drivers):
locks = hal.pm_locks()
# Explicit timed light sleep (returns wake reason / elapsed ms) or deep sleep:
hal.light_sleep(250)
# hal.deep_sleep(60_000) # Wake after 60 s
Automatic sleep_sec Display Dim & Idle Lifecycle
When cfg["sleep_sec"] > 0 is set in Settings or NVS, the OS shell smoothly dims the backlight at 75% of the idle timeout before calling hal.display_sleep(True) and engaging low-power governor thresholds — waking instantaneously on any key, touch, rotary detents, or button press.
2. ULP-RISC-V (ESP32-S3) & LP-Core (ESP32-C6) Coprocessors
Compiled with --enable-ulp, PylotOS exposes 16 shared 32-bit RTC slow-memory registers (hal.ulp_read_shared / hal.ulp_write_shared) so a tiny 7–15 µA ULP program can poll thresholds while the main cores sleep:
import hal
info = hal.ulp_info()
if info["supported"]:
hal.ulp_write_shared(0, 450) # Wake threshold passed to ULP
hal.ulp_load(ulp_riscv_bin)
hal.ulp_run(period_us=500_000, wake_deep_sleep=True)
samples = hal.ulp_read_shared(1)
3. Three Zero-Touch Wi-Fi Onboarding Flows
- In-Browser NVS v2 Pre-Provisioning (
pylotos.org/flash/): Generates a bit-exact24 KiBNVS partition in JavaScript (nvs_gen.js) before WebSerial flashing so the board joins Wi-Fi on its very first boot. - Captive Portal DNS (
:53,captive_dns.py): When unconfigured, PylotOS opens a SoftAP (PylotOS-<MAC4>) and answers DNS queries on UDP:53to pop up the Wi-Fi setup sheet automatically on iOS, Android, macOS, and Windows. - Improv Wi-Fi Standard (
improv.py— USB Serial & NimBLE BLE): Implements the open Improv Wi-Fi serial & GATT specification (00467768-6228-2272-4663-277478268000) for 1-click browser & Home Assistant provisioning.
Try the interactive Power & ULP dashboard in pylotos-sim:
pylotos-sim examples/power_sleep_and_ulp_monitor.py --board m5stack_stickc_plus2 --port 8080