-->
Page 1 of 3

Problems connecting a button to ESP8266.

PostPosted: Wed Jul 15, 2015 4:12 pm
by AlexPilk
I want to set up ESP8266 as an access point, connect a button to it and make it update the status of that button on it's server. I used Arduino IDE to program it, and it works, but there's a problem. If you power up the module while GPIO2 is connected to ground wifi doesn't work and the blue led is on constantly. With my setup it only works if you hold the button during the power up. Why does it behave like that and how do I fix it?
Here is my setup:

Image

And the code:
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char *ssid = "ESPap";
const char *password = "thereisnospoon";

int count = 0;
bool countalarm = 0;
String statustext = "sample";
ESP8266WebServer server(80);

void handleRoot() {
  server.send(200, "text/html", "Button's " + statustext + ". Button was pressed " + String(count) + " times");
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  pinMode(2, INPUT);
  WiFi.softAP(ssid, password);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  if(digitalRead(2)==1){
    statustext = "pressed";
    if(countalarm == 0){
    count+=1;
    }
    countalarm = 1;
  } else {
    statustext = "not pressed";
    countalarm = 0;
    }
   server.handleClient();
}

Re: Problems connecting a button to ESP8266.

PostPosted: Wed Jul 15, 2015 4:20 pm
by kolban
In your diagram, GPIO0 is dangling. You need to have it pulled high for normal booting.

Re: Problems connecting a button to ESP8266.

PostPosted: Thu Jul 16, 2015 1:40 am
by AlexPilk
Tried the same setup with GPIO0 connected to the power source, it's still the same. I can however boot with no problems if both GPIO0 and GPIO2 are dangling or pulled high. If I press that button when powering up and then release it - it works fine. But I'm wondering how to make it boot normally when the pin's grounded, or maybe there's another way to setup the button.

Re: Problems connecting a button to ESP8266.

PostPosted: Thu Jul 16, 2015 9:48 am
by martinayotte
Both GPIO0 and GPIO2 needs to be High for normal boot :

https://github.com/esp8266/esp8266-wiki ... ot-Process

So, it is normal that if you push the button on GPIO2 during power up, it doesn't boot.
Either you hookup the button on another GPIO (not available on ESP01) or you change your software to look at the button AFTER the power up, such as 1 second later.