Skip to content

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

Closed

Description

@Khorne13

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

Activity

  1. Khorne13 commented on May 14, 2017

    @Khorne13
    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

  2. RudyFiero commented on May 14, 2017

    @RudyFiero

    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.

  3. Khorne13 commented on May 14, 2017

    @Khorne13
    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

  4. WheresWally commented on May 14, 2017

    @WheresWally

    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
    
  5. igrr commented on May 14, 2017

    @igrr
    Member

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

  6. Khorne13 commented on May 14, 2017

    @Khorne13
    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.

  7. igrr commented on May 14, 2017

    @igrr
    Member

    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

  8. Khorne13 commented on May 14, 2017

    @Khorne13
    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

  9. WheresWally commented on May 14, 2017

    @WheresWally

    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.

  10. igrr commented on May 14, 2017

    @igrr
    Member

    Or rather,

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

    :)

  11. Khorne13 commented on May 14, 2017

    @Khorne13
    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.

  12. Khorne13 commented on May 14, 2017

    @Khorne13
    Author

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

  13. lights0123 commented on May 14, 2017

    @lights0123

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

  14. Khorne13 commented on May 14, 2017

    @Khorne13
    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 ..."

  15. Khorne13 commented on May 14, 2017

    @Khorne13
    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.

  16. 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))[/+] on May 14, 2017
  17. sebinbc commented on Oct 3, 2018

    @sebinbc

    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

  18. d-a-v commented on Oct 3, 2018

    @d-a-v
    Collaborator
    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();
        }
    
  19. moorthi5 commented on Dec 29, 2018

    @moorthi5

    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

  20. pieman64 commented on Dec 29, 2018

    @pieman64

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

  21. moorthi5 commented on Dec 29, 2018

    @moorthi5

    @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?

  22. pieman64 commented on Dec 29, 2018

    @pieman64

    @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.

  23. texsean commented on Mar 8, 2019

    @texsean

    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

  24. javadhabibi1500 commented on Jun 11, 2019

    @javadhabibi1500

    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

  25. BrunoPedro7 commented on Apr 10, 2020

    @BrunoPedro7

    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?

  26. raspiduino commented on Jul 22, 2020

    @raspiduino

    Just put this into loop():

    ESP.wdtFeed(); // feeds the dog
    delay(0);
    
  27. raspiduino commented on Jul 22, 2020

    @raspiduino

    I did it and it worked!

  28. JamesDelfini commented on Sep 11, 2022

    @JamesDelfini

    delay(0);

    What the heck it also works for me

  29. raspiduino commented on Sep 11, 2022

    @raspiduino

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions