Chat freely about anything...

User avatar
By Taher Kawantwala
#45670 Hello everyone.
I didn't find my answer anywhere so that's why I am posting my doubt here, If I'm duplication the thread then pardon me.
I am using ESP8266 ESP-12E. I have updated LED blinking code successfully using Arduino IDE 1.6.8. The sketch was working on ESP-12E board. Then I have tried ESP8266 WEBSERVER Example. I've uploaded the code successfully to ESP12E. After ESP12E reset i connect GPIO to VCC. I'm getting only garbage over terminal. Baud rate is 115200. I'm using LM1117 to power up ESP8266, and Using Prolific USB-RS232. ESP12E was working great with AT command with same power supply and USB-RS232 converter. I have connected GPIO0, RST and CH_PD to VCC with 10K pull UP.
I'm using this CODE:
Code: Select all/*
 *  This sketch demonstrates how to set up a simple HTTP-like server.
 *  The server will set a GPIO pin depending on the request
 *    http://server_ip/gpio/0 will set the GPIO2 low,
 *    http://server_ip/gpio/1 will set the GPIO2 high
 *  server_ip is the IP address of the ESP8266 module, will be
 *  printed to Serial when the module is connected.
 */

#include <ESP8266WiFi.h>

const char* ssid = "your_ssid";
const char* password = "your_password";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
 
  // 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.println(WiFi.localIP());
}

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 req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
 
  // Match the request
  int val;
  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;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
 
  client.flush();

  // Prepare the response
  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";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is detroyed
}
User avatar
By martinayotte
#45698 How did you attached the LED to GPIO2 ?

The problem is probably that you've connected the LEDs in Source mode (ie: anode to GPIO and cathode to GND).
This prevent the ESP to boot properly because those LEDs are acting as pulldown, while it is well known that both GPIO2/GPIO0 needs to be pulled up at reset or power-up to boot properly in Execution mode.

Read those threads, and connect your LEDs in Sink mode :
viewtopic.php?f=6&t=9454#p45277
viewtopic.php?f=13&t=7741#p39319
User avatar
By Taher Kawantwala
#45759
martinayotte wrote:How did you attached the LED to GPIO2 ?

The problem is probably that you've connected the LEDs in Source mode (ie: anode to GPIO and cathode to GND).
This prevent the ESP to boot properly because those LEDs are acting as pulldown, while it is well known that both GPIO2/GPIO0 needs to be pulled up at reset or power-up to boot properly in Execution mode.

Read those threads, and connect your LEDs in Sink mode :
viewtopic.php?f=6&t=9454#p45277
viewtopic.php?f=13&t=7741#p39319

Thanks for the reply, martinayotte.
I don't have connected LED to any GPIO PINS, GPIO0 and GPIO2 is Pulled High with 10K resistors. I just want to check ESP is working or not with this Web server Sketch. I have tried Connecting GPIO0 and GPIO2 directly to VCC (3V3).

After RESET ESP8266 is just throwing Garbage On terminal regardless of the Baud rate. I have tried Different USB-TTL converters too. have tried Different power supplies too with 800mA-1A power rating. still not getting anything on terminal but GARBAGE.