Post topics, source code that relate to the Arduino Platform

User avatar
By AlexPilk
#23363 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();
}
User avatar
By AlexPilk
#23387 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.
User avatar
By martinayotte
#23431 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.