micropython-pico-deepsleep icon indicating copy to clipboard operation
micropython-pico-deepsleep copied to clipboard

losing timing

Open oiuyulit opened this issue 2 years ago • 2 comments

I'm running a simple script and expiencing a loss of time over loops. I believe its around 1 second per picosleep.seconds call.

script I'm using:

from machine import Pin
#import picosleep
import utime
import picosleep

LED = machine.Pin(25,machine.Pin.OUT)
relay = machine.Pin(18, machine.Pin.OUT)

while True:

    LED.value(1)
    relay.value(1)
    picosleep.seconds(20)
    relay.value(0)
    LED.value(0)
    picosleep.seconds(10)

oiuyulit avatar Jul 09 '22 00:07 oiuyulit

Hi @oiuyulit , thanks for using this mod 🙂

Sorry to hear you're having problems. Do mean that say, if you ask it to sleep for 20 seconds, it will actually sleep for 21? Or will it only sleep for 19 seconds?

It might be that it's taking some time for the pico to reawaken after sleeping (if it's taking too long).

Or perhaps there is a delay from initialising the clock, and asking it to sleep (if it's not taking long enough).

The code is quite crude really.

Here we reinitialise the clock each time:

https://github.com/ghubcoder/micropython-pico-deepsleep/blob/3d3c7a336a58f544802db3f7ea44700495b3be73/ports/rp2sleep/modpicosleep.c#L79-L89

Here we increment the seconds based on what is passed in:

https://github.com/ghubcoder/micropython-pico-deepsleep/blob/3d3c7a336a58f544802db3f7ea44700495b3be73/ports/rp2sleep/modpicosleep.c#L37

Need to spend some time experimenting at some point and trying to improve things.

ghubcoder avatar Jul 31 '22 15:07 ghubcoder

@oiuyulit The official version of Micropython now support deep sleeping with this commit.

You can now use:

machine.lightsleep(5000)

For example to sleep for 5 seconds. Might be worth giving that a try to see if you are still losing timing.

ghubcoder avatar Aug 10 '22 18:08 ghubcoder