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);
}
ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Feb 15, 2024 at 10:09
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.

answered Feb 15, 2024 at 10:33
1
  • Thanks for the answer @chrisl. Of all the pins I could pick from! Commented Feb 16, 2024 at 1:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.