2017/06/03

ESP-01 - how to build a simple web server using Arduino - part 1 of 2

This is the first of a 2-part series on how to build a simple web server using ESP-01 and Arduino. The second part of this post is at  http://wei48221.blogspot.tw/2017/06/esp-01-how-to-build-simple-web-server_3.html.

The Schematics

First, wire up ESP-01 with CP-2102 as shown below.




Note,

After testing, it's possible to power ESP-01 with the +3V power output from CP-2102. Both the uploading of Arduino sketch to the on-board flash memory of ESP-01 and wifi transmission work correctly.

The Arduino Sketch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <ESP8266WiFi.h>

char* ssid = "YOUR_SSID";
char* password = "YOUR_PASSWORD";

void setup()
{
  WiFi.mode(WIFI_STA);      //We don't want the ESP to act as an AP
  WiFi.begin(ssid,password);
  Serial.begin(115200);
  while(WiFi.status()!=WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
}

Source: https://github.com/acrobotic/Ai_Tips_ESP8266/tree/master/simple_webserver

Note,

- Be sure to replace "YOUR_SSID" and  "YOUR_PASSWORD" with the SSID and the Password for the wireless router used.

- It's important to use "WiFi.mode(WIFI_STA)" to set ESP-01 to act as WiFi client only. If it's not used, ESP-01 will act as both an AP and a WiFi-client when connecting to a WiFi Router and that can mess up other WiFi-devices on your network. 

Procedure for uploading the Arduino Sketch

Be sure to do the following before uploading the sketch to ESP-01.

- Provide external +3.3V to ESP-01 (make sure the +3.3V is connected to VCC, and the GND is connected to GND). Or, power ESP-01 with the +3V power output from CP-2102.

- Plug the CP-2102 module to the USB port of the computer used for firmware upload;

- First close the flash switch then the reset switch so that both GPIO0 and RST of ESP-01 are connected to GND;

- First open the reset switch then the flash switch so that bboth GPIO0 and RST are floating;

- Click on the upload icon to compile and upload the sketch.

The result

After the sketch is uploaded successfully, open Serial Monitor (Tools -> Serial Monitor). If nothing happens, close then open the reset switch to reset ESP-01.


References:

ESP8266 Webserver Step-By-Step Using Arduino IDE (Mac and Windows)
https://www.youtube.com/watch?v=m2fEXhl70OY

No comments:

Post a Comment