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 · 23 comments

Comments

Projects
None yet
@Khorne13
Copy link

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link

commented May 14, 2017

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link

commented May 14, 2017

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

This comment has been minimized.

Copy link
Member

commented May 14, 2017

Or rather,

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

:)

@Khorne13

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

@lights0123

This comment has been minimized.

Copy link

commented May 14, 2017

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

@Khorne13

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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

This comment has been minimized.

Copy link
Author

commented May 14, 2017

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 May 15, 2017

@qwerty12345asdf

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link

commented Dec 29, 2018

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

This comment has been minimized.

Copy link

commented Dec 29, 2018

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

@moorthi5

This comment has been minimized.

Copy link

commented Dec 29, 2018

@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

This comment has been minimized.

Copy link

commented Dec 29, 2018

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jun 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.