Sleep experiments
-
Had some fun tonight with a very crude implementation of deep sleep, using the
esp_deep_sleep_enable_timer_wakeup(microsecs)
from ESP-IDF which I connected up to machine.deepsleep() - otherwise a no-op function at the moment.Turns out that for periodic wakeup we don't need a fully working RTC or to set up interrupts, the ESP32 provides a method which just takes a wakeup time in microseconds and it sets up everything to wake up the board automatically after that time has passed. According to the docs the RTC doesn't even need to be powered for this to work.
It's very simple to use, basically these two lines do all the work:
esp_deep_sleep_enable_timer_wakeup(time); esp_deep_sleep_start();
As I haven't added any wake up stub code the board does a reset once the time is up and starts running the main script again was usual. But just having it go to sleep and starting up automatically is already useful.
Example:
>>> machine.deepsleep(10) ets Jun 8 2016 00:22:57 rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:QIO, clock div:2 load:0x3fff9010,len:8
For reasons I'm not yet sure about the current during this sort of deep sleep mode is high, 22mA @ 3.3V, but still a big improvement over 100mA+ and maybe an option while we aren't able to turn off WiFi and real sleep modes.
This involves a small patch to mpsleep.c and a custom build of pycom-micropython. I did it to learn about the system and see what was possible to tweak -- and actually turns out it takes surprising little effort.
I'm sharing this in case anyone is interested - or if you're desperate to have some power savings at any cost :-)
Cheers
-
Seems a lot of new deep sleep modes have been added to ESP-IDF
http://esp-idf.readthedocs.io/en/latest/api/system/deep_sleep.html
as a fantastic example:
The following wake up sources are configured:
Timer: wake up the chip in 20 seconds
EXT1: wake up the chip if any of the two buttons are pressed (GPIO25, GPIO26)
Touch: wake up the chip if any of the touch pads are pressed (GPIO32, GPIO33)
ULP: wake up when the chip temperature changes by more than ~5 degrees Celsius (this value hasn't been characterized exactly yet).Can't wait to see this in μPython :-)
-
Btw. has time.sleep(60) any power saving functions or is it comparable with delay(60000); in the Arduino world?
-
@jmarcelino - this is very cool, would so love to be able to machine.deepsleep(xxxx).
I have been waiting for RTC interrupts to come out so I could 'shut down' 99% of the day, being able to do this without RTC would be very, very neat !
Power consumption is critical to me for my current project, and this would go a long way to helping.
-
@jmarcelino
this is really interesting
especially that this is another deep sleep mode without RTC
I supose that with diabled WiFi the current should be really minimal - it sounds very optymistic
i suppose @administrators should look at thisi also go in that direction i see what can be tuned :)