button and led problem on boot ESP-01
Posted: Tue Apr 21, 2015 4:36 am
Hi, I've the next code:
I've a led connected to a pull down resistor to the GPIO 2, and a button connected to the GPIO 0 and a pull down resistor to ground, something like that:
but to a ESP-01 obviusly.
When the system is up, i can turn on/off the led by url:
http://192.168.1.2/gpio/1
http://192.168.1.2/gpio/0
or by the button.
The problem i've is that i need to unplug both resistor, power the board and then plug the resistors. If i try to boot the board with the resistors connected, doesn't boot (no ping and no button working). What i need to do to boot with the resistors pluged?
Code: Select all
#include <ESP8266WiFi.h>
const char* ssid = "myssid";
const char* password = "mypass";
WiFiServer server(80);
int val=0;
int buttonState = 0;
int lastButtonState = 0;
void setup() {
Serial.begin(115200);
delay(10);
pinMode(2, OUTPUT);
pinMode(0, INPUT);
digitalWrite(2, 0);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());
}
void loop() {
buttonState = digitalRead(0);
if (buttonState == HIGH && lastButtonState == LOW) {
delay(100);
if (val == 0) {
digitalWrite(2, HIGH);
val = 1;
}
else {
digitalWrite(2, LOW);
val = 0;
}
}
lastButtonState = buttonState;
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("new client");
while(!client.available()){
delay(1);
}
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
digitalWrite(2, val);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
client.print(s);
delay(1);
Serial.println("Client disconnected");
}
I've a led connected to a pull down resistor to the GPIO 2, and a button connected to the GPIO 0 and a pull down resistor to ground, something like that:
but to a ESP-01 obviusly.
When the system is up, i can turn on/off the led by url:
http://192.168.1.2/gpio/1
http://192.168.1.2/gpio/0
or by the button.
The problem i've is that i need to unplug both resistor, power the board and then plug the resistors. If i try to boot the board with the resistors connected, doesn't boot (no ping and no button working). What i need to do to boot with the resistors pluged?