ESP8266 getResetReason() - wrong result

Hello friends of excited electrons,

I’m using the ESP8266-07 with the Arduino library.

I would like to distinguish between a power-on reset and an external-reset with a button.
Reset (RST) pin of ESP8266 is pulled up to VCC with 10k. If the button is pressed it’s tied to GND.

So I searched for a while in the web and found following solution:

#include <Arduino.h>
extern "C" {
#include <user_interface.h>
}

void setup() {

  rst_info *resetInfo;
  Serial.begin(9600);  
  resetInfo = ESP.getResetInfoPtr();
  Serial.println((*resetInfo).reason);

}

void loop() {
  // put your main code here, to run repeatedly:
}

However I get always reset code 6, independent of if I unplug (and replug) power or push the button.
I've awaited, that I get reset code 0 if the device is powered up.

https://github.com/esp8266/Arduino/blob/master/tools/sdk/include/user_interface.h

enum rst_reason {
 REASON_DEFAULT_RST = 0, /* normal startup by power on */
 REASON_WDT_RST = 1, /* hardware watch dog reset */
 REASON_EXCEPTION_RST = 2, /* exception reset, GPIO status won’t change */
 REASON_SOFT_WDT_RST   = 3, /* software watch dog reset, GPIO status won’t change */
 REASON_SOFT_RESTART = 4, /* software restart ,system_restart , GPIO status won’t change */
 REASON_DEEP_SLEEP_AWAKE = 5, /* wake up from deep-sleep */
 REASON_EXT_SYS_RST      = 6 /* external system reset */
};

Now I'm sad :sob:
What am I doing wrong?

Software Versions:
Arduino IDE: 1.6.13
Board: ESP8266 version 2.3.0

EDIT: sry for misleadig title. "getResetReason()" is also a method which returns a human readable representation of reset code. However its derived from rst_info and yields the same wrong result.

  Serial.println((*resetInfo).reason);

Most people would have used

  Serial.println(resetInfo->reason);

Why didn't you? Just curious.

In short: I dont know.
Think its a personal style and sometimes I forget that there is an arrow operator. But I will change it for bette readability.

Unfortunately this wont solve the problem ... :slightly_frowning_face:

Search in electrical circuit

reason.jpg

Did you ever resolve this issue? I have a similar issue. I'm not using a pull-up resistor & the reset works fine, but I'm finding that I get a response of 5 when I do an external system reset when the chip is in deepsleep.

I think the usb->serial device resets the controller when it connects to the device. So you think you're power cycling but once the power has come back on again, the PC connection then resets the device and actually gives you a code 6.

You could write some code that turns on the LED if you have reason 6, then reset the device without the PC connection (obviously you'd need some kind of LCD to get the exact number or even a webpage giving you the reason).

I'm just starting out on the same functionality, I'll let you know how I get on.

It is possible to disable the auto reset function too.
https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection

Hi @sevenOFnine,
I found a solution to get reset code 0. It needs "EN" pin to connect RC delay circuit. I think because of current surge and power instability at boot, it gets reset code 6 instead of 0.

In datasheet, R = 10KOhm and C = 0.1uF are recommended but I have to change capacitor value to 1uF because 0.1uF didn't work for me.
I tested with ESP-01 module. Hope it works out for you. :smiley:

REF:
CH_EN and RST pin connection
(https://www.espressif.com/sites/default/files/documentation/esp8266_hardware_design_guidelines_en.pdf)