esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
15.96k stars 13.34k forks source link

ESP.deepSleep not able to wake up device #5892

Closed mikegron closed 5 years ago

mikegron commented 5 years ago

Basic Infos

Platform

Settings in IDE

Problem Description

I'm trying to make deep sleep work as intended. I made a very simple sketch that just sleeps for 30 seconds. I've attached a wire from D0 to the RST pin so that the deep sleep timer could reset the board. I am connected/powered via USB.

After the specified time, a LOW signal is correctly sent to the D0 pin as the device write the boot information but nothing else is happening afterward, I have to unplug the power or manually reset the board with the reset button. I tested with 115200 or 74880 bauds if that makes a difference, to see the boot info which is in 74880.

My board is setup exactly like this: ESP8266 Deep Sleep with Arduino IDE

Sketch


void setup() {
  Serial.begin(74880);
  Serial.setTimeout(2000);
  while (!Serial) { }
  Serial.println("Started.");
  delay(5000);
  Serial.println("Going to sleep.");
  ESP.deepSleep(30e6);
}

void loop() { }

Debug Messages

image

5chufti commented 5 years ago

try putting a delay(10) after the ESP.deepSleep()

liebman commented 5 years ago

Looking at the log messages this is working correctly. Deep sleep does not continue from the sleep, it starts with setup again. It’s basically a reset. If you have data you want to persist then you need to use RTC memory or flash. EDIT:Ok I failed to read the annotations on the log. Forget I commented. :-/

mikegron commented 5 years ago

Hmm if I remove the cable from D0 to RST I still have the "ets Jan..." message so I guess this is printed on wake and not when receiving a reset signal. I tried resetting "manually" by hooking RST to ground and that works, I still have the same boot message but the board starts properly. So maybe D0 simply does not send the wake (LOW) signal??

fsommer1968 commented 5 years ago

I use the following pin configuration for DO: pinMode(D0, WAKEUP_PULLUP); In addition instead of a direct connection from DO to RST I use a Schottky Diode (preferred) or a 680Ohm resistor.

fsommer1968 commented 5 years ago

I recommend closing this issue

mikegron commented 5 years ago

Setting the pin to WAKEUP_PULLUP did not change the behaviour unfortunately. Could you tell me why would adding a resistor between D0 and RST fix that? Also as a test, setting D0 to INPUT made the board go in a reset loop (so it looks like it can work).

fsommer1968 commented 5 years ago

Wake up pin is Nodemcu pin D0 which is 8266 pin GPIO16. You are referring to GPIO_0 , this is not the Wakeup pin! Check your wiring and pin assignment: https://randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide/ Without a resistor or diode the wiring from D0 to RST should be removed during flashing the module. In my opinion Nodemcu V3 modules have a high quiescent current. I use e.g. Wemos D1 mini which has a low dropout voltage regulator for battery applications.

mikegron commented 5 years ago

My bad for referring to GPIO_0, indeed I meant D0 (GPIO_16), I used the same exact link you posted (I also linked it in the problem description) Pictures just to be sure: DSC_1240 DSC_1243

mikegron commented 5 years ago

It looks like the board is waking up in flash mode somehow, same as if I hold the flash button at the same time as the reset button. Although I did try setting D3 (GPIO 0) and D4 (GPIO 2) as INPUT_PULLUP, or attaching a cable from 3.3V to D3 (to make sure it's high). I have no ideas now..

devyte commented 5 years ago

Are you physically resetting the board after flashing over serial?

mikegron commented 5 years ago

Yeah, I also tried using a power supply, same result :/

fsommer1968 commented 5 years ago

I tried with a Nodemcu 0.9 (ESP12) module and the connection from DO to RST, and you sketch works: 17:00:32.789 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6) 17:00:32.789 -> 17:00:32.789 -> load 0x4010f000, len 1384, room 16 17:00:32.789 -> tail 8 17:00:32.789 -> chksum 0x2d 17:00:32.789 -> csum 0x2d 17:00:32.789 -> v951aeffa 17:00:32.789 -> ~ld 17:00:32.857 -> Started. 17:00:37.853 -> Going to sleep. 17:01:06.604 -> 17:01:06.604 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6) 17:01:06.604 -> 17:01:06.604 -> load 0x4010f000, len 1384, room 16 17:01:06.639 -> tail 8 17:01:06.639 -> chksum 0x2d 17:01:06.639 -> csum 0x2d 17:01:06.639 -> v951aeffa 17:01:06.639 -> ~ld 17:01:06.706 -> Started. 17:01:11.687 -> Going to sleep.

But when i forget the connection from D0 to RST this happens: 17:01:45.529 -> Going to sleep. 17:02:14.316 -> 17:02:14.316 -> ets Jan 8 2013,rst cause:5, boot mode:(3,6) 17:02:14.316 -> 17:02:14.316 -> ets_main.c

So from my point of view there might be something with your board or the board description in Arduino for the ESP12E module is wrong.

mikegron commented 5 years ago

Thank you for testing! There is probably something wrong with the board you're right.. I checked the pins (with nothing else connected) with a multimeter and I find the measures odd: The RST pin always stays at 3.3V. When running, the D0 pin is at 0V. When sleeping, the D0 pin is at 3.3V. When waking up, the D0 pin is set to 0V continuously. However, to wake the board with the RST pin, I need to set it to 3.3V -> 0V -> 3.3V. For instance, connecting RST to ground does not reset the board, but removing the connection will reset it. But, disconnecting the D0 pin while it's at 0V does not have the same effect (like if 0V was not gound). Do you see anything wrong with that?

fsommer1968 commented 5 years ago

Hm measuring dynamic signals with a multimeter where typically a logic analyser, a scope, or at least a logic tester is required is not more than a bad guess. I think you should look around for other using Nodemcu V3 with Deep Sleep. I have described what I was able to test (in addition Wemos D1 mini works well with DS, too). And so far I cannot see that there is something wrong with this Arduino release for 8266. As explained earlier: maybe the board description needs an update for this specific board. I would look for the schematics of this board to check, set the board in the Arduino GUI to to generic 8266 and set each option manually. If you are not able to do this, go and take a 8266 board that is proven to work.

mikegron commented 5 years ago

Ok so I tested the exact same sketch with a Wemos D1 R1 and it worked perfectly... I'm gonna close this issue and try to figure out what is wrong with the NodeMcu v3 ! Thanks a lot for your help.

5chufti commented 5 years ago

To me that is an old version where the reset circuit does prevent the pulse form gpio16 to be recognized correctly. The new nodemcus have a different layout with one free (not assembled) resistor location to bridge when using deep sleep

petrilloa commented 5 years ago

I have a similar issue with a bunch of ESP12F from Espressif. We build more than 100 sensors with ESP12F from AI, and doesn´t have any problem to wake up from deep sleep, GPIO16 direct connection to RESET. With the new batch, the factory send us ESP8266MOD (phisically looks the same as the old ones, and justo like an ESP12F), but trying a simple sketch to wake up, the devices hangs until we press reset.

We have a 3.3v from MCP1700, 1000uF and 0.1nF capacitor from VCC to GND. (input 3xAA Batteries) GPIO15 pulldown with 10k GPIO0 pullup with 10k GPIO2 pullup with 10k

To connect the reset we try...

1-Connect Reset to GPIO16 with wire 2-Connect Reset to GPIO with 330 ohms resistor 3-Connect Reset to GPIO with Diode (normal and schottky).

Debbug:

AI ESP8266 12-F (WORKING)

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v951aeffa ~ld Chip ID: 276350

ResetInfo.reason = 5: Deep-Sleep Wake . I'm awake. Going into deep sleep for 3 seconds

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v951aeffa ~ld Chip ID: 276350

ResetInfo.reason = 5: Deep-Sleep Wake . I'm awake. Going into deep sleep for 3 seconds

Espressif ESP8266 12-F (NOT WORKING)

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v951aeffa ~ld Chip ID: 6198051

ResetInfo.reason = 5: Deep-Sleep Wake . I'm awake. Going into deep sleep for 3 seconds

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

Please any help!?

fsommer1968 commented 5 years ago

Hi petrilloa, that is sad! Try to get schematics for both boards and compare them. Beside the GPIO16 and reset I would check the SPI flash connection.

petrilloa commented 5 years ago

There is a custom PCB, with a bare ESP12F. Si there is not diff schematics.

Skipper-is commented 5 years ago

Same board, Lolin NodeMCU v3. Exactly the same issue. I've got 3 of the same board, and they all exhibit the same behaviour described here.

ArsineMan commented 5 years ago

Same Problem. I purchased 10 of these guys. So far 3 are functional and 4 are not. I literally just plug them into the same breadboard location and load the exact same sketch. I stuck an oscilloscope on the D0 pin and noted the working boards do drop all the way to 0 whereas the broken ones do not.

devimc commented 5 years ago

I updated my platformio framework and its packages (framework-arduinoespressif8266) and now I'm facing this issues :cry: , but if I revert everything to 2018-12-03, ESP.deepSleep works again :smile: , this means that something changed in the library or toolchain :thinking:

ArsineMan commented 5 years ago

@devimc, that's interesting. I assumed it was my hardware so I bought from a different vendor and its started working.

ptutt1 commented 5 years ago

I have a Lolin Nodemcu v3 and have same issue as described. Will enter deep sleep but will not come out. Interestingly, it is drawing around 72ma when running, then around 250ua when in deep sleep. After it attempts to wake up, I can see the on board led flash, it uses around 36ma. My guess is as other has mentioned it wakes into flash state. I also find that I have to press the reset button twice to wake it from deep sleep. I can also need to ground RST twice to exit deepsleep.

I also captured D0 output on oscilloscope and can see it seems to be correctly grounding to trigger the reset, but as mentioned, if reset needs to happen twice, then it's not going to work.

IMG_20190819_135027

Easiest fix seems to be getting new hardware that supports deepsleep properly.

5chufti commented 5 years ago

have a look at #6007

magc2806 commented 4 years ago

Hello ! I am having this exact problem with my Amica NodeMCU Esp8266. Has anyone found a solution for this or I must change my board? How do I know my board's version ? And which ones dont have this problem? thank you in advance

ptutt1 commented 4 years ago

@magc2806 in my case I purchased a WeMos ESP8266 D1 Mini and there was no problem. My problem was with the Lolin Nodemcu v3 but I can't comment on other boards.

magc2806 commented 4 years ago

Thanks a lot for your reply @ptutt1 . Have you tried the sleep mode with another NodeMCU v3?

ISObob21 commented 4 years ago

I have the same problem with the Lolin NODEMCU V3, the wide unit. Load same code onto a DoIt ESP12E Devkit V2, 22mm wide unit, and all is well.

allexb commented 4 years ago

The same problem for me. LoLin new NodeMcu V3 (ESP8266MOD)

worksasdesigned commented 3 years ago

Same issue with the "xxxxMOD" Version. 12F is running perfectly smooth.
Just took me 4 hours to find this post and another 5 min to exchange the WeMos with an other batch.

Craig1516 commented 3 years ago

I am revisiting two, or three, batches of ESP12's from 2019'ish. Some work after deepsleep, some do not. Double resets do work, but... the first reset ends badly with high power consumption (33 mA). Sadly, my QC is sloppy and I have several protypes on several boards from several purchased batches. And with 16 surface mounts these chips do not come off the PCB nicely. Testing, testing, testing... so important.

ole1986 commented 3 years ago

I also noted the same. While using deep sleep in a short period (1 min) it seem to work AS expected.

When I use deep sleep for 1h with a powerbank as power supply it never wake up.

5chufti commented 3 years ago

did you check that it is not the powerbank that shuts down and hinders the esp to wake up?

ole1986 commented 3 years ago

I have now double checked while connecting to debugging computer for more than an hour. Unfortunately it keeps staying in deep sleep.

Trying to reduce it to 30 minutes now!

Below is the code example and output

// where settingData.interval is 60 minutes
Serial.println("Going into deep sleep for " + String(settingData.interval) + " minutes");
ESP.deepSleep(settingData.interval * 60 * 1000000);

Output

Going into deep sleep for 60 minutes
Craig1516 commented 3 years ago

Seems like 30 minutes should work for you. I think the max sleep time is a bit over 35 minutes. The technicals (2^31) are discussed here.

Maybe your powerbank as mentioned by Schufti? A multimeter should show you if that is the problem.

Craig1516 commented 3 years ago

Here is another fun story. He found that by swapping to a different ESP it solved his sleep problem.

ole1986 commented 2 years ago

As a side note. It's wasnt the powerbank but the esp when configuring it to approximately 1 hour.

When setting up to 30 min deep sleep and wake up works so far with the powerbank

But shouldn't it be a 64bit range with newest API?

FBMinis commented 1 year ago

I have just landed here from Google and it was the powerbank that would allow the ESP-07S to deepsleep. After testing with a phone charger and 2xAA it worked.

amadeuspzs commented 6 months ago

Can confirm this behaviour with some implementations of ESP8266MOD on a Wemos D1 Mini clone.

Trying on a NodeMCU (ESP-12F) worked, so it does look like, while frustrating and somewhat incomprehensible, different hardware implementations affect the correct functioning of deepSleep mode.

For anyone else facing this issue, try a different hardware implementation.

Edit: it appears this is a known issue for D1 Mini's:

Some ESP8266s have an onboard USB chip (e.g. D1 mini) on the chips’ control line that is connected to the RST pin. This enables the flasher to reboot the ESP when required. This may interfere with deep sleep on some devices and prevent the ESP from waking when it’s powered through its USB connector. Powering the ESP from a separate 3.3V source connected to the 3.3V pin and GND will solve this issue. In these cases, using a USB to TTL adapter will allow you to log ESP activity.

From https://esphome.io/components/deep_sleep.html

jtauscher commented 1 month ago

Issue can be fixed by adding 10k resistor to second pin (GPIO7) next to the 3.3V pin.

20240719_121049

TomasBelo commented 1 month ago

@jtauscher Thanks! This fixed the issue.

5chufti commented 1 month ago

do yourself a favour and use the technically correct method to connect rst and gpio16: a schottky diode, cathode (ring) to gpio16 (despite what the datasheet says); this will greatly improve your flashing (and wakeup) experience.

lionel-gattegno commented 1 month ago

Hi @5chufti can you please elaborate? how will it improve flashing and wakeup experience? (I'm brand new to electronics and super interested to learn...)

5chufti commented 1 month ago

Hi @5chufti can you please elaborate? how will it improve flashing and wakeup experience? (I'm brand new to electronics and super interested to learn...)

a) with hard link, external reset circuitry will 99.9% fail to reset ESP module (has to work against "strong HIGH" from gpio16 , so automatic flashing from IDE will work at all. b) with resistor, external reset circuitry will still have to work against "strong HIGH" from gpio16 through resistor. Experience shows that experimental values for resistor may work with one batch of modules but fail on other.

with diode, both cases are solved electronically correct and compatible with 99.9% modules encountered.

jtauscher commented 1 month ago

I don't think a diode will solve this issue. It's not a problem of RST or GPIO16.

5chufti commented 1 month ago

there are modules with "suboptimal" internal circuitry on rst (RC network) which react erratically to the reset signal from gpio16 as allready discovered and discussed on gh in history. They suffer due to misshaped (thus shortened) pules on rst. Even this might improve with any action to keep pulse (edge) in shape! p.s.: I never hinted that it solves the problem with improper load / incompatible flash ic (?) on sd_d0 - but that it is general good practise to design circuits according to minimal electronic standards keeping singal levels in mind.

jtauscher commented 1 month ago

For my experience the pulse is too short or not "low enough". So maybe you are right but still I don't understand how a diode would help. With the additional R at GPIO7 it simply helps to get a decent LOW at RST. It worked for me on 2 modules so far. So it seems to be the simplest and yet reliable solution.

5chufti commented 1 month ago

I really can't see how a pull-up on gpio7 can improve the timing related to gpio16/rst. I think that there is a more complex underlying problem that keeps the esp from properly starting up after the wake-up reset. One would have to decap the module and replace the flash for a known good one to get a more clear picture. Or experiment with differend flash modes or ...

p.s.: and it most likely is no new problem, there have been lots of reports on "zombie mode" in former days of esp hype.