← index #16180Issue #16519
Related · high · value 2.824
QUERY · ISSUE

lightsleep() not working properly Pi Pico WH v1.24.0

openby RYoder97opened 2024-11-07updated 2025-03-03
bugport-rp2

Port, board and/or hardware

Raspberry Pi Pico WH

MicroPython version

MicroPython v1.24.0 on 2024-10-25; Raspberry Pi Pico W with RP2040

Reproduction

Attempt following code, both with lightsleep() having no ms argument and one with:

import machine
from machine import Pin, deepsleep, lightsleep

def wake_up(pin):
    # Handle wake-up logic here
    led.toggle()
    print("Button pressed, waking up!")

# Configure buttons
button = Pin(11, Pin.IN, Pin.PULL_UP) # Example pin
led    = Pin(20, Pin.OUT)

led.on()

# Set up interrupt
button.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=wake_up)

# Go to sleep until a button is pressed
lightsleep()

Expected behaviour

Expect LED to react to button press when asleep and execute wake_up function. LED is on by default. LED should toggle/turn off when button is pressed down, both when machine is asleep and not asleep.

Observed behaviour

USB power tester indicates that the board sleeps only when NO MILLISECONDS ARGUMENT IS SPECIFIED.

When milliseconds ARE SPECIFIED, board does not appear to sleep as power consumption does not drop according to the USB tester. The board continues to work at full power, and the LED reacts to the button.

When NO MILLISECONDS ARE SPECIFIED, board appears to go to sleep (reducing power from >10ma to 0-1ma. But button does not do anything to LED.

Additional Information

I have tried adding the wake argument to button.irq, but Micropython says that extra keyword arguments are present.

I understand sleeping may have issues on the Pico W models. I have also tried turning off WiFi/setting the pin associated with Wifi to "low". That does not seem to have any impact whatsoever, since my code never explicitly turns Wifi on

https://forums.raspberrypi.com/viewtopic.php?p=2266590#p2266590

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

RP2: machine.RTC().datetime() does not advance during lightsleep

openby madozuopened 2025-01-03updated 2025-12-13
bugport-rp2

Port, board and/or hardware

Raspberry Pi Pico W and Raspberry Pi Pico 2 W

MicroPython version

All versions starting with v1.24.0 (including recently released v1.26.0)

Reproduction

  1. Copy code below to Pico and name it "main.py"
  2. Reset the Pico and allow the code to complete (approx 5 seconds). No repl needed as the code writes a log file to the flash storage
  3. Connect the Pico to the USB port and inspect the file "local.log" on the Pico

Code used to test:

# Test RTC sleep behaviour
import machine, os, time

SLEEP_MS = const(2000)

def write_log(s: str) -> None:
    dt = machine.RTC().datetime()
    log_text = f"[RTC={dt[4]:02d}:{dt[5]:02d}:{dt[6]:02d} ticks={time.ticks_ms()}]  {s}"
    with open("local.log", "a") as file:
        file.write(log_text + "\n")

write_log(f"Machine = '{os.uname()[4]}'")
write_log(f"Version = '{os.uname()[3]}'")
time.sleep_ms(SLEEP_MS)
write_log(f"After time.sleep_ms({SLEEP_MS})")
machine.lightsleep(SLEEP_MS)
write_log(f"After machine.lightsleep({SLEEP_MS})")

Expected behaviour

The real time clock should advance by 2 seconds after running 'machine.lightsleep(2000)' like it was on micropython versions up to and including 1.23.0. Example output from 1.23.0:

[RTC=00:00:01 ticks=49]  Machine = 'Raspberry Pi Pico W with RP2040'
[RTC=00:00:01 ticks=54]  Version = 'v1.23.0 on 2024-06-02 (GNU 13.2.0 MinSizeRel)'
[RTC=00:00:03 ticks=2058]  After time.sleep_ms(2000)
[RTC=00:00:05 ticks=4065]  After safe_sleep(2000) with 0 early wakeups

Observed behaviour

The real time clock does not advance during machine.lightsleep(2000) as shown below running on 1.26.0:

[RTC=00:00:01 ticks=36]  Machine = 'Raspberry Pi Pico W with RP2040'
[RTC=00:00:01 ticks=42]  Version = 'v1.26.0 on 2025-08-09 (GNU 14.2.0 MinSizeRel)'
[RTC=00:00:03 ticks=2033]  After time.sleep_ms(2000)
[RTC=00:00:03 ticks=4037]  After machine.lightsleep(2000)

Additional Information

While machine.RTC().datetime() does not advance during machine.lightsleep(), time.ticks_ms advances as expected.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied