Page 1 of 1

deepsleep at the wrong end

Posted: Sun Jan 16, 2022 11:51 pm
by KJM
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?

Re: deepsleep at the wrong end

Posted: Mon Jan 17, 2022 12:47 am
by davef
Maybe looking at the reset state using different reset modes might provide a clue. Does the reset button do a machine.reset()?

Re: deepsleep at the wrong end

Posted: Mon Jan 17, 2022 5:11 am
by KJM
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.

Re: deepsleep at the wrong end

Posted: Mon Jan 17, 2022 8:50 pm
by KJM
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?

Re: deepsleep at the wrong end

Posted: Mon Jan 17, 2022 9:26 pm
by davef
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