0

I have a KY-040 rotary encoder with a push button wired to an ESP8266. My objective is to be able to detect if the button is pressed or not on boot.

In the below code, if I hold the button down and power on the ESP8266, neither "IT'S STARTED" or "IT'S LOOPING" is printed in the serial monitor, even if I release the button. If I don't press the button, the code works as expected and prints "IT'S STARTED" followed by "IT'S LOOPING". It's as though the code gets stuck/halted if I press the button on boot.

Can someone explain why this is happening?

I would also appreciate suggestions on how I can detect the status (pressed/not pressed) of the button when the ESP8266 is powered up.

Here is my code:

void setup() {
  pinMode(D3, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.println("IT'S STARTED");
}

void loop() {
  Serial.println("IT'S LOOPING");
  delay(1000);
}
1

1 Answer 1

4

Description of pin D3 from this ESP8266 pinout reference:

connected to FLASH button, boot fails if pulled LOW

So you cannot pull this pin to LOW during boot, as it will keep the ESP in flash mode. You need to use a pin, that doesn't have this limitation, like D1, D2, D5, D6 or D7.

1
  • Thanks for the answer @chrisl. Of all the pins I could pick from! Commented Feb 16 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.