Sleeping a handheld device

:grimacing: :thinking: :upside_down_face: :exploding_head: Update…

Lots of video reviews lead me to start trying what seemed to be a straightforward set of functions designed to sleep and wake my ESP8285.

None of them would compile …


Although I have finally gotten these functions to compile I have not yet verified they actually work.

As you can see they are a mixture of gpio, ESP. class and system functions.
I found these by just typing ESP., gpio and system and watching what the IDE function reference revealed then trying to compile.

Some were also found by disecting “low power demo” programs in the examples for the board core I am using.

For some reason the gpio_xx_xx functions need the ESP8266WIFI.h to compile. I will research this more later but for now I am taking it.

//These only compile with the “#include <ESP8266WiFi.h”>
gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_UP_PIN), GPIO_PIN_INTR_LOLEVEL); // GPIO wakeup (optional)

gpio_pin_wakeup_enable(GPIO_ID_PIN(16), GPIO_PIN_INTR_LOLEVEL); // GPIO wakeup (optional)
//Some info suggests that GPIO16 cannot be used as wakeup.

gpio_pin_wakeup_disable();

//These compile without "#include <ESP8266WiFi.h> "
ESP.deepSleep(0); // must have a value (0). Waits for wifi shutdown
ESP.getChipId(); // just interesting nothing to do with sleep
ESP.deepSleepInstant(0); // instantly enters deep sleep, does not wait for wifi shutdown.
system_deep_sleep_instant(0); // same as ESP.deepSleep()?

My plan is to test:
Enter deep sleep when no buttons on the device are pushed for a programmed amount of time.
Then cycle the power switch to reset the device.

------------ MORE ---------------------

What a convoluted challenge this is. The documentation on the ESP8285 and ESP8266 are confusing especially related to “sleep and wakeup”.

I am using a WEMOS DI mini lite which is an ESP8285. I am using this because it fits the cost, power and package size needed for my handheld.

I also have tried a D1 mini which is an ESP-12S [ESP8266EX]

Tons of research suggested that both these ESP derivatives could be put into deep sleep and then wake’t up via a timed value or a predefined I/O transition.

Things that you need to know about your setup:
What processor is actually in your board [especially if you are buying knockoffs; ESP Tool

What board core are you using and what functions are in the associated library:
https://arduino-esp8266.readthedocs.io/en/3.1.2/libraries.html
https://arduino-esp8266.readthedocs.io/en/latest/
The “ESP-specific APIs” section was the most useful.

1 Like

Hi,

A few years ago I spent a lot of time trying deepsleep with ESP8266. I found the following limitations:

  • duration of sleep is limited to 71minutes (which is too short)
  • breadboards with ESP8266 eat a lot of juice even in deepsleep (up to 20mA)

So I finally gave up to go to the much better ESP32…

However before doing this I had success with the following schematics:

A few words of explainations:

  • Q1 is P channel Mosfet which is normally “off” unless you pull down its gate to ground
  • this can be done manually by a switch SW
  • this can also be done by the N channel Mosfet Q3

And Q3 can be driven by a pin of ESP8266

So that you manually start the ESP8266 by pushing a button (SW grounded)
you keep it pressed a few milli seconds until ESP8266 boots. Immediately into the setup you drive the PIN GPIO14 to high which in turn, switches on the mosfet Q3 and pulls Q1 gate to ground. You can then safely release the button and your ESP8266 will remain powered until you decide (by code) to switch GPIO14 as an input…Q3 will close, Q1 gate will rise to high and Q1 will block cutting power of your ESP8266. No juice eaten during deepsleep !

I don’t know if this could fit your needs but for low powered devices manually triggered it is perfect (buttons, doorbells, mail box, eScale… plenty of use cases!)

Don, I googled github for the esp8285 and looked through projects until I came across a battery powered one. This uses 3uA sleep mode so the source might be helpful in solving your API problems.

Thanks @dougl @freedom2000
I will take a look at those projects.

So I tried deep sleep and it worked! Sort of!

I ran a loop and after 10 cycles I asserted ESP.DeepSleepInstant(0);
It clearly went to sleep.
I woke it with a power cycle.

Not elegant but for this tool/project’s use case I think it will suffice.
I planned on the power switch anyway since the display has no sleep or hardware reset :grimacing:.

Note: I will clean up the display on power up.

Never using ESP8285/66 again!

3 Likes