Dear Arduino and microcontroller enthusiasts,
In my journey to learn more every week I want to learn how to work with the ESP8266 / ESP-01.
What I have done is the following:
I connected an 5v FTDI to my laptop and only connected the Tx and Rx.
Added a led to the GPIO2 port.
Used a separate power source 3v to connect the Vcc+CHPD and GND.
with the following code
// https://diyhacking.com/esp8266-tutorial/
// GPIO0 = GPIO0 (need to have pull-up resistors connected to ensure the module starts up correctly)
// TX = GPIO1 (used as the Data line, will get some debug output on GPIO1 on power up)
// GPIO2 = GPIO2 (need to have pull-up resistors connected to ensure the module starts up correctly)
// RX = GPIO3 (best practice = input) (will be output HIGH on startup)
#include <ESP8266WiFi.h>
const char* ssid = "OhNoYouDidnt";//type your ssid
const char* password = "yesidid";//type your password
int ledPin = 2; // GPIO2 of ESP8266
WiFiServer server(80);//Service Port
void setup() {
Serial.begin(115200);
// Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY); // needed for to use Rx as input pin
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
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");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1){
digitalWrite(ledPin, LOW);
value = LOW;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
if(value == HIGH) {
client.println("<a href=\"/LED=OFF\"><button onclick="">On</button></a>");
} else {
client.println("<a href=\"/LED=ON\"><button onclick="">Off</button></a>");
}
client.println("</html>");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
}
To upload:
I power the ESP8266 on.
I connect the GP0 to the GND and shortly touch the RST to the GND.
Then set the Arduino IDE to ESP8266 module and hit upload.
Works perfect!
I can go to the IP address in my browser and turn on and off the LED.
Then the problem
I want to connect a relay and the future application must be reliable.
So from 'the internet' I recover the best practice and add 2 pull-up resistors 47k from GP2 and GP0.
So I boot again, everything works can still flip the LED.
So now I connect the relay to a 5v power source and also join the GND.
I remove the LED and plug the Relay module signal on the place of the LED.
It still works.....
But then It will not reboot properly.
What I now have:
I have the feeling that I miss something...
What am I doing wrong?
Thanks in advance!
Picture of the breadboard: