Problems connecting a button to ESP8266.
Posted: Wed Jul 15, 2015 4:12 pm
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:
And the code:
Here is my setup:
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();
}