esp32 (nodemcu) and machine.lightsleep(3000) not waking up

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
eradicatore
Posts: 52
Joined: Thu Apr 20, 2017 9:19 pm

esp32 (nodemcu) and machine.lightsleep(3000) not waking up

Post by eradicatore » Tue Apr 14, 2020 1:53 pm

Hi,
I have been testing with machine.deepsleep(3000) and it works. I see with a crude measuring device that during the 3 seconds it's at 10mA. I wanted to see what machine.lightsleep(3000) did with RAM staying up, and see if ble connected any faster after it was over (since it doesn't have to start from reset every time) and for some odd reason the machine.lightsleep(3000) never wakes up again.

I looked at the ways to setup the wake trigger to ext0, ext1, and touch. But I didn't see one to explicitly call out RTC. So do I have to do that explicitly? I didn't for deepsleep().

Here is my code snippet:

Code: Select all

def demo():
    time.sleep_ms(200)

    ledpin = machine.Pin(2, machine.Pin.OUT)

    ble = bluetooth.BLE()
    temp = BLETemperature(ble)

    network.WLAN(0).active(0)
    network.WLAN(1).active(0)

    t = 25
    i = 0
    total = 0

    while True:
        ledpin.on()

        while total <20:
            # Write every second, notify every N seconds.
            total = total + 1
            i = (i + 1) % 1
            temp.set_temperature(t, notify=i == 0)
            # Random walk the temperature.
            t += random.uniform(-0.5, 0.5)
            time.sleep_ms(800)

        ledpin.off()
        machine.lightsleep(3000)



eradicatore
Posts: 52
Joined: Thu Apr 20, 2017 9:19 pm

Re: esp32 (nodemcu) and machine.lightsleep(3000) not waking up

Post by eradicatore » Tue Apr 14, 2020 6:26 pm

Ok, in playing with this more, I'm starting to convince myself that maybe the input parameter to this lightsleep() is seconds?

I noticed as I let the board just sit there it was doing *something*. So I changed 3000 to 3 even though the documentation here:

https://docs.micropython.org/en/latest/ ... chine.html

shows it's supposed to take milliseconds. Then I got what I can only describe as an unreliable approximate 3 seconds. I realize the RTC is probably not all that precise. No worries. But sometimes it went 13 seconds?! This last many times its been right around 3 seconds. Anyway, just odd. Any words of wisdom would be appreciated.

In testing with my usb current drain tester, it shows no real current drain savings when in this lightsleep(). Odd. I was expecting something closer to deep sleep for some reason. I guess that was wishful thinking.

User avatar
tve
Posts: 211
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: esp32 (nodemcu) and machine.lightsleep(3000) not waking up

Post by tve » Tue Apr 14, 2020 10:05 pm

Looking at the code, the timeout definitely is in milliseconds. I have not used that call myself, so can't really comment from experience. I have done quite some work on low power modes, see https://github.com/micropython/micropython/pull/5473 and the docs that go with it: https://micropython-tve.readthedocs.io/ ... 2-lowpower

When you write "I see with a crude measuring device that during the 3 seconds it's at 10mA" is that a typo and should read 10 microamps? 'Cause 10ma is way too much. See https://blog.voneicken.com/2018/lp-wifi-esp32-boards/ for some background.

eradicatore
Posts: 52
Joined: Thu Apr 20, 2017 9:19 pm

Re: esp32 (nodemcu) and machine.lightsleep(3000) not waking up

Post by eradicatore » Fri Apr 17, 2020 1:43 pm

Thanks for the reply @tve! I'll read your PR and docs and see if that helps. When I mention the current drain, I am using this device:

https://www.droking.com/usb-tester/Digi ... anel-Meter

It only goes down to 10's of mA (.01 A is what I read for deepsleep()). I am on a nodemcu, and I do know that those devices aren't very optimized for low power with their other components supporting the esp32. So I will try to get a better setup to read out true power soon. I have done a daughterboard for the nodemcu that uses this circuit so I hope to be able to completely latch off all current when "not in use" sort of thing.

https://randomnerdtutorials.com/latchin ... 6-arduino/

The reason I'm looking at lightsleep() right now is that I am using ble when awake, but I want to still sleep when awake if nothing is changing. I was thinking lightsleep() could keep the RAM up so ble would maybe keep it's connection or reconnect even faster?

Post Reply