ESP8266 Tutorial Part I – Getting Started

Hello everyone! Cytron Technologies has brought you another small and yet fantastic module Wifi Serial Transceiver ESP8266!! Don’t under estimate the capabilities of this small module, it can give you more than you can imagine! Ever think about making your own web server at your room, or control your appliances at your house even though you are far away from your home, but at the same time you don’t want to spend a lot to make all these stuffs? Good news is, this small amazing module can be low cost solution you are seeking for! Besides that, it is easy to learn and use too. Getting interested? Come, let’s get started and know more about it. This tutorial will teach you some basics on how to use this module by giving AT command through UART communication.

Before we get this ESP8266 WiFi module powered up and ready, we have to assemble all necessary hardware all together. Let’s take a closer look on this module and its pinouts.

The picture below shows the basic connection between the ESP8266 WiFi module and other hardware.

ESP8266 WiFi Module

Connection

VCC

+3.3V

GND

GND

RX

TX of UART device

TX

RX of UART device

CH_PD

+3.3V

GPIO0

NC

GPIO2

NC

RST

NC

Note:

TX and RX serial connections ‘crossover’ is a must, i.e RX pin of ESP8266 module must be connected to TX pin of other UART device or vice versa. Not crossing over is a common mistake when first hooking up a serial communications device. In this tutorial we are going to connect ESP8266 with USB to UART converter.

ESP8266 is 3.3V compatible only device so don’t try to power up the device directly with power supply more than 3.3V or you will damage the module. Voltage regulator is needed if you tend to use power supply more than 3.3V.

Make sure UART device can provide RX and TX signal with +3.3V logic level as well or else voltage level shifter is needed. Most microcontrollers such as Arduino and PIC provides RX and TX with 5V logic so don’t make RX and TX connections directly!

Setup time!!

Now let’s start assembling the circuit and power up the module!!

Step 1:

Prepare two set of male header pins (each with 5 pins) and USB to UART converter. Use soldering tool to solder them up as shown in the picture. Once finished, the USB to UART converter is ready to be placed at breadboard.

Step 2:

Connect the ESP8266 WiFi module with USB to UART converter using male to female jumper. Further, connect the rest of the components as well such as 3.3V voltage regulator, capacitors, etc. The connection of the circuit is shown in the picture below.

Step 3:

Slide the slide switch on the USB to UART converter to the position labelled with 3.3V so that RX and TX signals are +3.3V level logic. (Note: USB to UART converter does not come with slide switch, so make sure you solder it on your own)

Step 4:

Connect the USB to UART converter to your computer using USB MiniB cable. Turn on the switch on breadboard to power up the module.

If you can see red light turn on permanently and blue light flashes, it means your module is ready to use!!

OK we have done with the hardware setup. Let’s give a try to this module!!

This module supports UART communication, and you can use any serial monitor software to communicate with this module. In this tutorial, we are going to use RealTerm software as communication tool. If you still don’t have this software, click here to download.

Once you have opened the software, you should be seeing a black display screen and few tabs beneath it. Switch to Port tab.

To establish a connection between PC and ESP8266 module, there are a few things you have to take note:

Port

Baudrate

Parity

Data Bits

Stop Bits

Checking the COM Port

Port refers to COM port. Which port we are going to choose depends on which COM port your device (USB to UART converter) is connecting to. To check it out, simply right click My Computer -> Properties -> Device Manager. You can check the COM port your device is connecting at Ports (COM & LPT). In this tutorial, the device is connected to COM7.

Once finished, click the Open button. You will get a visual that the button is being pressed.

Testing ESP8266

Switch to Send Tab, this is where you start talking to module and tell it what to do. Here we will be giving AT command to this module and the module will respond to each command we entered if the command is correct.

Let’s greet the module by giving some command. First type AT into the textbox, and make sure you check +CR and +LF at EOL category as shown in the picture below. This will automatically add Carriage Return and Line Feed to the whatever we type in textbox before PC send them to the ESP8266.

After you have done, click Send ASCII.

If you receive OK at display screen, congratulations! You have successfully ‘talk’ to the module!!

More commands to ESP8266!!

Of course ESP8266 is not designed to just give you an ‘OK’. Now it is ready for more commands from you and it will execute the tasks according to the AT commands you have entered. (and of course AT command must be correct). Below is a list of AT commands you can play with ESP8266. (Click here for AT command list pdf file)

Let’s make a simple web server using AT commands!!

Let’s put some AT commands into application! OK now we are going to make this ESP8266 a simple web server. Whoever browses for this server will see “Hello World” on the webpage. Let’s try it!

Step 1: Setting working mode

First of all, send AT+CWMODE? to check the ESP8266 module working mode. By default you should be getting response +CWMODE:2 and OK. Send AT+CWMODE=1 or AT+CWMODE=3 to configure this module to be able to join another WiFi access point. (1 = join other WiFi access point (AP) only, 3 = join other WiFi AP + serves as an WiFi AP)

If you get OK response, it means the module has been configured successfully.

Step 2: Joining a Network

Let’s try to get ESP8266 module to join one of the WiFi network. First send AT+CWLAP to search for WiFi network available. After a few seconds, a list of WiFi networks within ESP8266 module range should be shown.

If you are getting ERROR response, try to repeat Step 1 then try again.

Now pick a network you would like to join. The name of the network shown is the network SSID and you will have to know the password for the particular network in order to proceed.

Once you have both network SSID and password, send this command

AT+CWJAP=” your network SSID”, your network password”

For example, your network SSID is ALIBABA and the password is 12345. So you should type AT+CWJAP=”ALIBABA”,”12345″

It might take a while to get a response. If you receive OK response again, then the module has successfully joined the network.

By now the module should have an IP address in the network, let’s check it out by sending AT+CIFSR. You should be getting 192.168.1.xxx from the response. That is the IP address assigned to the module by the router. Remember this IP address because we will need it later. In this tutorial the IP address is 192.168.1.143.

Step 3: Setup ESP8266 as TCP server

To setup a web server, first of all send AT+CIPMUX=1 to turn on multiple connection to this module.

Next send

AT+CIPSERVER=1,(your desired port number)

Standard port number is 80 but you can insert any other numbers other than that. Let’s say if you set port number = 9999, later on when you access to the IP address, you should be typing 192.168.1.xxx:9999. In this tutorial, we will using standard port 80, we send

AT+CIPSERVER=1,80

If you receive OK response, the module is ready.

Step 4: Access ESP8266 server from browser as client

Open a web browser(Chrome, Mozilla FireFox) and type the IP address of the module into the URL bar on the browser. In this tutorial, the IP address assigned is 192.168.1.143. BTW, your computer must also connected to the your WiFi network, in my case, the computer is connected to “Cytron-Asus” network.

Now check the display screen of RealTerm software. You should be seeing data streaming in and ending with “Link” word! Meaning the module has already received request from you.(You just browse for ESP8266 server remember?)

OK next let’s send “Hello World” back to the client so those words can be displayed on the webpage. Following command will be used.

AT+CIPSEND=<id>,<data length>

<id> refers to +IPD,<id>,.. from the data streaming in just now and data length refers to how many characters from the data that ESP8266 server is going to send.

In this tutorial, we receive +IPD,0,.. so <id> is 0. “Hello World” consists of 11 characters (including space) so <data length> would be 11. Therefore, we send AT+CIPSEND=0,11

Once “>” appears from the response, it means you can start type the data you want to send, but within the limit we have set just now. Let’s type “Hello World” and send. After that send AT+CIPCLOSE=<id> where <id> refers to the <id> we used in AT+CIPSEND command. In this tutorial we send AT+CIPCLOSE=0

Hello World appears on the webpage!! Congratulations, you have successfully created a ESP8266 server which can show Hello World to all clients who access it!!

Conclusion

The use of ESP8266 WiFi module has been increasing in wireless technology and it has potential to offer low cost and yet amazing solution for the users to develop their own networking applications. Besides, IoT(Internet of Things) has also become famous and this module shows good potential as well to be applied in this application. In this tutorial, we have made a first step in communicating with this module and make a simple server out of it!! Yet it still can offer more, and we still can make more use of it, such as combining it with other application processor to develop useful network application etc. Hope you enjoy this tutorial. Happy Experimenting!!

If you have any inquiry, please post in our technical forum as we seldom check the comments section in tutorial site 🙂