Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] ESP8266 12E keeps rebooting (rst cause:2, boot mode:(3,6)) #3241

Closed
Khorne13 opened this issue May 14, 2017 · 28 comments
Closed

[Solved] ESP8266 12E keeps rebooting (rst cause:2, boot mode:(3,6)) #3241

Khorne13 opened this issue May 14, 2017 · 28 comments

Comments

@Khorne13
Copy link

Khorne13 commented May 14, 2017

Hello,
I want to use my ESP8266 12E with a keypad, I wired it this way:
1-----D0
2-----Rx
3-----SD3
4-----D3
5-----D4
6-----D5
7-----D6
8-----D7

I didn't use the D1 and D2 because I want to add an LCD I2C later.

Well, first I tried this code, same wiring it works perfectly:

#include <Keypad.h>
 
const byte n_rows = 4;
const byte n_cols = 4;
 
char keys[n_rows][n_cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
 
byte colPins[n_rows] = {D3, 10, 03, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
 
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols); 
 
void setup(){
  Serial.begin(115200);
}
 
void loop(){
  char myKey = myKeypad.getKey();
 
  if (myKey != NULL){
    Serial.print("Key pressed: ");
    Serial.println(myKey);
  }
}

But later in my project I will need to use another commands and somethings, so I used this one, very similar

`#include <Keypad.h>
 
const byte n_rows = 4;
const byte n_cols = 4;
 
char keys[n_rows][n_cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
 
byte colPins[n_rows] = {D3, 10, 03, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
 
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols); 
 
void setup(){
  Serial.begin(115200);
}
 
void loop(){
           char keypressed = myKeypad.waitForKey();
         if (keypressed != NO_KEY)
             {
             char c1 = keypressed;
              Serial.println(c1);
              }
}

But when I upload this on the board, the board starts rebooting, and I get this in the serial monitor

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

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

I'm powering it from my computer, and as you can see all I did is changing a function and add a variable
Thanks

@Khorne13
Copy link
Author

Same wiring same all, the problem starts if I change the function "getkey" to "waitForKey" I don't know why, the function waitForKey stops the program and wait until a key is pressed, not like "getkey" that keeps the programme looping

@RudyFiero
Copy link

Include a delay in the routine. That would allow background tasks that need to run. You can not have long blocking code with the ESP8266. It will cause the behavior you see.

@Khorne13
Copy link
Author

Yes I noticed if I keep pressing buttons from the keypad the board doesn't reboot until I stop for few seconds.
Is there a way to increase that rebooting perdiod, like from 2seconds to 10 or more seconds, it would be great for me if it waited few seconds more before rebooting?
Thanks

@WheresWally
Copy link

WheresWally commented May 14, 2017

If you load the original sketch, is all ok then?

reset causes:
    0: 
    1: normal boot
    2: reset pin
    3: software reset
    4: watchdog reset

boot device:
    0:
    1: ram
    3: flash - See more at: http://www.esp8266.com/viewtopic.php?p=2096#p2112

@igrr
Copy link
Member

igrr commented May 14, 2017

Pin 10 is used to connect flash memory inside the esp12 module, I doubt it can be used for other purposes.

@Khorne13
Copy link
Author

As you can see I kept the same wiring, even if I used the pin 10, the first code works fine but the second one keeps rebooting if I don't press buttons quickly, the problem appears if I change the function I mentionned above.

I've read about a reset period that can be modified, but I don't have further information about it. If you know please tell me, thanks.

@igrr
Copy link
Member

igrr commented May 14, 2017

Ok, sorry, missed that part.

Keypad::waitForKey method in Keypad library is not compatible with the ESP8266 Arduino core because it uses a busy loop. This part of the code library needs to be modified, by inserting a delay(0); or yield();:
https://github.com/Chris--A/Keypad/blob/master/src/Keypad.cpp#L211-L215

@Khorne13
Copy link
Author

Oh, I'm a beginner, I didn't understand what you meant...
Should I remove the keypad "waitforkey" function, or should I modify something to be able to use it?
Thanks

@WheresWally
Copy link

The codes are :

0 -> normal startup by power on
1 -> hardware watch dog reset
2 -> software watch dog reset (From an exception)
3 -> software watch dog reset system_restart (Possibly unfed watchdog got angry)
4 -> soft restart (Possibly with a restart command)
5 -> wake up from deep-sleep
Looking at the provided code you can decide from what reason the chip is restarting.

I found that loops need a yield() to be ESP8266 friendly, to feed the watchdog before it triggers.
the line referred to by Igrr ...
while( (waitKey = getKey()) == NO_KEY ); // Block everything while waiting for a keypress.
most likely should be ...
while( (waitKey = getKey()) == NO_KEY ) yield(); // Block everything while waiting for a keypress.

@igrr
Copy link
Member

igrr commented May 14, 2017

Or rather,

while( (waitKey = getKey()) == NO_KEY ) yield(); // DON'T block everything while waiting for a keypress.

:)

@Khorne13
Copy link
Author

If it doesn't block the program, it would be like the function getKey() and this one make a little mess in my program, I really want the program to wait like 5s or more in this step before looping again.

I want the program to wait a key then store it into a char c1, then wait another key and store it into char c2 ... So I can do other things later. If I use the function "getkey" it mess with my program: I can only store one char, because the program doesn't wait. (to explain my little idea).

And how can I modify the library if I want to test your solution.

Thanks guys.

@Khorne13
Copy link
Author

I downloaded that library by using the "library manager" method, where can I find the cpp file so I can modify it?
Thanks

@lights0123
Copy link

It is in the folder under your sketchbook location, so probably Documents/Arduino/libraries/Keypad/Keypad.cpp.

@Khorne13
Copy link
Author

No didn't find it there.
I have found that library on the arduino library "Program files - Arduino - Libraries"
Because I tried first time with an Arduino UNO, then when I used the NodeMcu I had that library problem and I downloaded it using the library manager.
"I don't know if both uses the same library, or the NodeMcu ones are saved in another place like wifi libraries ..."

@Khorne13
Copy link
Author

Hello everyone,
So it seems it works fine,
For everyone having the same problem: I did a copy of the library (so not to ruin it), then I opened the file keypad.cpp with note++, I did the modification proposed by "WheresWally" and "igrr", then I saved the .cpp file as Keypad2 and renamed the keypad.h to keypad2.h, then I kept the same second code mentionned above, now I can store 2 keys as c1 and c2 and manipulate them with using the modified version of "waitForKey" function.

You guys thanks so much you're really helpful.

@Khorne13 Khorne13 changed the title ESP8266 12E keeps rebooting (rst cause:2, boot mode:(3,6)) [Solved] ESP8266 12E keeps rebooting (rst cause:2, boot mode:(3,6)) May 14, 2017
@igrr igrr closed this as completed May 15, 2017
@sebinbc
Copy link

sebinbc commented Oct 3, 2018

If we are calling the yield() function in the "Keypad.cpp" file should we not have some code associated with it too what i mean is
void yield(){
//something that the function does//
}
Or should we just call it and save it and hope it works in the final compilation on the arduino ide.
One more final comment :
how should we call the yield() if the while loop is like this:=
while(some condition){
//some work//
};
Thanks.
Ps. I am facing similar problem while working with a finger print sensor library here https://github.com/sparkfun/Fingerprint_Scanner-TTL

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 3, 2018

while (some condition) {
    yield();
    //some work//
}

yield() is a "system" function that should be called regularly if you are stuck in your loop() function.
In the arduino model we should try to not be stuck, then it usually is

void loop() {
    // stuff
    if (some condition) {
        //some work//
    }
    // stuff
}

You can consider that system is doing this:

    setup();
    while (true) {
        loop();
        yield();
    }

@moorthi5
Copy link

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

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

Hello guys ,anyone help me , i have used Esp12e after uploading iot code its continuesly rebooting ,not connect mqtt ,what to do? How to solve

@pieman64
Copy link

@moorthi5 please create your own issue with all the required details.

@moorthi5
Copy link

@pieman64 i was doing home appliance control threw google assistant using iot platform ,i was used Esp12e board ,after uploading code ,wifi connection properly conneting local hotspot ,but mqtt not connecting ,, board working properly while see serial monitor following cmt only continuously reboot
ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

Where is problem i can't find ,board or code?

@pieman64
Copy link

@moorthi5 there are lots of reasons for a device reset and that's why you must create a NEW issue with all the required details.

@texsean
Copy link

texsean commented Mar 8, 2019

mine was also giving the same error in the serial monitor but kept failing to upload, I was about to give up and just throw it away when I found this page, I fixed it and wanted to share in case someone else has a esp8266 that always fails to download no matter what you try, reboot power down another port hit flash button, nothing worked. sooo.. I hooked a wire to ground and touched every pin (BUT vin and 3.3v) as that would be stupid. this somehow "fixed" my device for some reason. I suspect it was one of the 2 reserve pins. if anyone knows why this desparate measure fixed my bricked node ecu please chime in!

update, a program caused this semi bricked state, this time I did one pin at a time and found ground to CMD resets it and lets you upload again! yay

@javadhabibi1500
Copy link

Include a delay in the routine. That would allow background tasks that need to run. You can not have long blocking code with the ESP8266. It will cause the behavior you see.

Adding a 1ms delay worked for me.
Thanks

@BrunoPedro7
Copy link

Include a delay in the routine. That would allow background tasks that need to run. You can not have long blocking code with the ESP8266. It will cause the behavior you see.

Adding a 1ms delay worked for me.
Thanks

Where did you add it?

@raspiduino
Copy link

raspiduino commented Jul 22, 2020

Just put this into loop():

ESP.wdtFeed(); // feeds the dog
delay(0);

@raspiduino
Copy link

I did it and it worked!

@JamesDelfini
Copy link

delay(0);

What the heck it also works for me

@raspiduino
Copy link

raspiduino commented Sep 11, 2022

delay(0);

What the heck it also works for me

:))

Idk
Sth just works but can't be explained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests