Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rp2040 light_sleep did not restore clocks #8561

Closed
Sokoloft opened this issue Nov 5, 2023 · 2 comments · Fixed by #10018
Closed

rp2040 light_sleep did not restore clocks #8561

Sokoloft opened this issue Nov 5, 2023 · 2 comments · Fixed by #10018
Labels
Milestone

Comments

@Sokoloft
Copy link

Sokoloft commented Nov 5, 2023

CircuitPython version

Adafruit CircuitPython 9.0.0-alpha.2 on 2023-10-27; Adafruit Feather RP2040 with rp2040

Code/REPL

# import
import alarm
import board
import pwmio
#import simpleio
import time

# Time values set by user
seconds = 10 #testing
minutes = 0
hours = 0
days = 0

# math
minute = minutes * 60
hour = hours * 3600
day = days * 86400
val = minute + hour + day

# power on tone

# simpleio
#simpleio.tone(board.A0, 1000, duration=0.5)

# pwmio
piezo = pwmio.PWMOut(board.A0, duty_cycle=0, frequency=440, variable_frequency=False)
piezo.duty_cycle = 65535 // 2  # On 50%
time.sleep(1)
piezo.duty_cycle = 0 # off

# wait for timer
print("Sleeping for", val, "seconds...")
#time.sleep(seconds)
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + seconds)
alarm.light_sleep_until_alarms(time_alarm)
while True:
    print("Beeping...")
    #simpleio.tone(board.A0, 1000, duration=0.5)
    piezo.duty_cycle = 65535 // 2  # On 50%
    time.sleep(1)
    piezo.duty_cycle = 0 # off
    time.sleep(1)

Behavior

The code runs through. In the loop, I receive unexpected behavior with my attached piezo beeper not beeping as it should.

Description

With simpleio, I will receive a beep from the piezo beeper under #power on tone. However once alarm is called and woken back up. In the loop I only get the print statement. No tone from the piezo beeper. This persists until the hardware is reset.

With pwmio, I again receive the beep under #power on tone at its stated frequency. After alarm, I will receive the print statement in console many times before I hear a tone from the piezo beeper. The tone is not at its stated frequency and is higher pitched. The tone is also on longer than one second. The tone seems to toggle off after the loop has gone around 3 times. Reloading the code in REPL, I do not receive the #power on tone, I do however eventually get beeping from the loop with the same behavior described. It takes a hardware reset to hear the #power on tone again.

I've tried both circuitpython stable release 8.2.7, and now the alpha 9.x release. Both have the same outcome.

Additional information

No response

@Sokoloft Sokoloft added the bug label Nov 5, 2023
@dhalbert dhalbert added this to the 9.0.0 milestone Nov 5, 2023
@tannewt tannewt added the rp2040 Raspberry Pi RP2040 label Nov 6, 2023
@Sokoloft
Copy link
Author

Sokoloft commented Nov 12, 2023

Hello.

I've found a work around that requires deep sleep. I was confused as to how to implement it at first. However this is what I have and it works as intended.

# import
import alarm
import board
import simpleio
import time

# Time values set by user
seconds = 10 #testing
minutes = 1
hours = 0
days = 0

# math
minute = minutes * 60
hour = hours * 3600
day = days * 86400
val = seconds + minute + hour + day

time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + val)
print(alarm.wake_alarm)

if alarm.wake_alarm == None:
    # power on tone

    # simpleio
    print("Power on tone")
    simpleio.tone(board.A0, 1000, duration=0.5)

    # wait for timer
    print("Sleeping for", val, "seconds...")
    alarm.exit_and_deep_sleep_until_alarms(time_alarm)

else:
    while True:
        print("Beeping...")
        simpleio.tone(board.A0, 1000, duration=1)
        time.sleep(1)

@dhalbert dhalbert modified the milestones: 9.0.0, 9.x.x Dec 1, 2023
@bradanlane
Copy link

I just encounter this issue with PWM based sound after loading alarm.

Additionally, I edited my code.py to no longer use alarm and the problem remained until I power cycled the board. Once I power cycled the board, the PWM sound worked as expected.

@dhalbert dhalbert changed the title Alarm and pwmio/simpleio rp2040 light_sleep did not restore clocks Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants