deepsleep at the wrong end

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

deepsleep at the wrong end

Post by KJM » Sun Jan 16, 2022 11:51 pm

I've got upython program that reads a few sensor then deepsleeps for 20 mins, rinse & repeat. On the pycom device I developed it on it would run at power up then deepsleep, so the sequence was, run, deepsleep, run, deepsleep,..... On the D32 Lolin board it deepsleeps at powerup then runs, so the sequence is deepsleep, run, deepsleep, run, .... I mean it works but having to wait 20 minutes after powerup to see if it works is a pain.

I've tried pressing the reset button after power up but it still insists on doing the deepsleep first. Any ideas for making it run first deepsleep later?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: deepsleep at the wrong end

Post by davef » Mon Jan 17, 2022 12:47 am

Maybe looking at the reset state using different reset modes might provide a clue. Does the reset button do a machine.reset()?

KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: deepsleep at the wrong end

Post by KJM » Mon Jan 17, 2022 5:11 am

After pressing the reset button machine.reset_cause() returns a 1 which is supposedly PWRON_reset. The only 2 reset_cause that make sense are 3 & 4 for wdt & deepsleep respectively. The others are all over the place, 5 gets returned for a soft reset (ctrlD) or a power up, I've never seen a 2 which should be for a hard reset.

Now that I look at this problem more closely I see it actually waits for 2 deepsleeps on powerup. Because it behaves differently when plugged into the USB I'm reduced to trying to intuit what's going on via the led. If I set the led to come on just before deepsleep then at powerup I get a deepsleep with the led on, then another deepsleep with the led off, then the normal run, sleep cycle begins.

KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: deepsleep at the wrong end

Post by KJM » Mon Jan 17, 2022 8:50 pm

I ran a short (12 line) test program & it runs OK from power up so my problem is related to the program size (400 lines). Seems bizarre that behaviour from power up is dependant on program size?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: deepsleep at the wrong end

Post by davef » Mon Jan 17, 2022 9:26 pm

The reason I moved from ESP8266 to ESP32.
Are you running gc.collect() at points through your program. There are some commands:
import micropython
micropython.mem_info()

# setting a threshold for gc.collect()
gc.threshold(gc.mem_free()) // 4 + gc.mem_alloc()
that are supposed to be useful.

BTW, I am currently trying to debug an application and machine.reset() is not the same as hitting the enable button on my ESP32_Devkitc_V4

Post Reply