I'm trying to get my ESP8266 into a deep sleep (you are feeling sleepy!) with this code:
#include void setup() { Serial.begin(115200); while (!Serial) {} delay(500); if (!wifi_set_opmode(WIFI_STA)) { Serial.println("Error setting WiFi mode to station"); return; } Serial.print("SDK: "); Serial.println(system_get_sdk_version()); // Disable WiFi before sleep. wifi_station_disconnect(); wifi_set_opmode(NULL_MODE); wifi_set_sleep_type(MODEM_SLEEP_T); Serial.println("Sleeping for 10s"); system_deep_sleep(10e6); } void loop() { }
It goes to sleep and wakes up approximately 10s later. However, the serial monitor shows garbage:
The boards LED lights up and stays on forever and nothing else seems to happen. I can't tell if the microcontroller has crashed or not. Is there anything obviously wrong with my code?
Thanks
First thing is, do you have GPIO 16 connected to the reset pin? When it wakes, there is a flag that tells GPIO 16 to go low and it will reset.
You could also try:
ESP.deepSleep(10e6);
I hope this helps.
I have a wire from RST to D0 (GPIO-16) on the dev board. I'll try your suggestion, but I'm trying to stick to the original ESP8266 SDK for now while I learn:
ESP.deepSleep(10e6);
Thanks
Ok, the ESP.deepSleep call works, though I still get some garbage in the serial monitor:
19:25:50.300 -> ⸮
I'll have to look at the code in the ESP library to see what it is doing differently to my code.
Thanks
If I remember correctly, isn't there always a little bit of garbled communication when you reset an esp? It is physically resetting so that might be normal. From what I understand, the bootloader sends the messages at 74880 baud. You might try and set your sketch to that as well and I'd be interested to know what it actually says.
Edit: A little more digging and I found out that it is a boot message from ROM and therefore "Espressif can't deactivate it...". It is supposed to list the output log info on the reset cause and boot mode. More in depth here.
Interesting, thanks.
I found that this code works by itself:
system_deep_sleep_set_option(RF_DEFAULT); system_deep_sleep(30e6);
I get the following output if I set the serial monitor speed to 74880 baud:
19:49:01.283 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
19:49:01.283 ->
19:49:01.283 -> load 0x4010f000, len 3584, room 16
19:49:01.283 -> tail 0
19:49:01.283 -> chksum 0xb0
19:49:01.329 -> csum 0xb0
19:49:01.329 -> v2843a5ac
19:49:01.329 -> ~ld
Ugh. I had my ESP8266 in a breadboard, and I had the two pins connected. Unfortunately I think the ESP8266 possibly wasn't seating properly in the breadboard and I wasn't getting a good connection with the RST pin and the wire. So I took it and wired it up away from the breadboard and now it works. Wasted evening but better to know what the problem was.