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);
}
-
2D3 is io 0 the boot mode pin. arduino.stackexchange.com/questions/75704/…Juraj– Juraj ♦02/15/2024 10:33:55Commented Feb 15, 2024 at 10:33
1 Answer 1
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.
-
Thanks for the answer @chrisl. Of all the pins I could pick from!Lachlan Etherton– Lachlan Etherton02/16/2024 01:54:25Commented Feb 16, 2024 at 1:54