Dark Light

Getting Started With the ESP8266 Leave a comment

Theย ESP8266 ESP-01ย is a Wi-Fi module that allowsย microcontrollersย access to aย Wi-Fi network. This module is a self-containedย SOCย (System On a Chip) that doesnโ€™t necessarily need a microcontroller to manipulate inputs and outputs as you would normally do with anย Arduino, for example, because the ESP-01 acts as a small computer. Depending on the version of the ESP8266, it is possible to have up to 9 GPIOs (General Purpose Input Output). Thus, we can give a microcontroller internet access like the Wi-Fi shield does to the Arduino, or we can simply program the ESP8266 to not only have access to a Wi-Fi network, but to act as a microcontroller as well. This makes the ESP8266 very versatile, and it can save you some money and space in your projects.

In this tutorial we are going to show you how to set up the ESP-01 Wi-Fi module, configure it, and verify that there is communication established between the module and another device.

Step 1: Materials

These are the components that you will need:

  • ESP8266 Wi-Fi Module ESP-01
  • Male/female jumper wires
  • Breadboard
  • Arduino UNO

Step 2: ESP-01 Setup

exp10_has_1

When you buy theย ESP8266 ESP-01, it comes with a pre-installedย AT firmware. It is possible to program the chip with another firmware such asย NodeMCU, for example. However, AT firmware is compatible with theย Arduino IDE, so we are going to use this firmware for this tutorial. If you want to know how to install a different firmware, then read the Miscellaneous section in this tutorial.

First use the jumper wires to connect the Wi-Fi module to the Arduino as shown in these images.ย 

exp10_has_a

exp10_has_b

exp10_has_c

Step 3: ESP-01 Setup continued

Upload theย BareMinimumย example to ensure that no previous programs are running and using the serial communication channel. Next, open the serial monitor and type the following command:

AT

You should get an โ€œOKโ€ response. This means that the module is working and that you are good to go. Now we are ready to test a two way communication between the module and another device.

Step 4: Basic AT Commands

The ESP8266 ESP-01 module has three operation modes:

  1. Access Point (AP)
  2. Station (STA)
  3. Both

Inย APย the Wi-Fi module acts as a Wi-Fi network, or access point (hence the name), allowing other devices to connect to it. This does not mean that you will be able to check your Facebook from your device while the ESP-01 module is operating in the AP mode. It simply establishes a two way communication between the ESP8266 and the device that is connected to it via Wi-Fi.

Inย STAย mode, the ESP-01 can connect to an AP such as the Wi-Fi network from your house. This allows any device connected to that network to communicate with the module.

The third mode of operation permits the module to act as both an AP and a STA.

Step 5: Basic AT Commands – STA Mode

In this tutorial, we are going to set the module to operate inย STAย mode by typing the following command:

AT+CWMODE=1

The corresponding number for each mode of operation is as follows:

  • STA = 1
  • AP = 2
  • Both = 3

Step 6: Basic AT Commands – Check Mode

If you want to check what mode yourย Wi-Fi moduleย is in, you can simply type the following command:

AT+CWMODE?

This will display a number (1, 2, or 3) associated with the corresponding mode of operation.

Step 7: Basic AT Commands – Connecting Wi-Fi Network

Once we have theย ESP-01ย operating inย STAย mode, we need to connect to aย Wi-Fi network. First we can check if we are already connected to one by sending the command:

AT+CIFSR

This will display the stationย IP addressย of our ESP-01 module. If you donโ€™t get an IP address after entering the previous command, use the following command to connect to your network:

AT+CWJAP= โ€œWi-FiNetworkโ€,โ€œPasswordโ€

Type the name of your Wi-Fi network and the password to connect to it. Make sure you include the quotation marks. After a couple of seconds, you should get an “OK” response. You can check again to see if you have an IP address using the AT+CIFSR command.

Step 8: Basic AT Commands – Enable Connections

Then we need to enable multiple connections before we can configure the ESP8266 ESP-01 module as aย server. Type the next command:

AT+CIPMUX=1

Once again, each number is associated with a type of connection:

  • Single = 0
  • Multiple = 1

The following step is to start the server at port 80:

AT+CIPSERVER=1,80

The first number is used to indicate whether we want toย close server modeย (0), orย open server modeย (1). The second number indicates the port that the client uses to connect to a server. We chose port 80 because this is the default port forย HTTP protocol.

Step 9: Basic At Commands – Response

exp10_has_3

Now, when we open aย web browserย and type the IP address of our ESP module we get the following response as shown in the image above.

This is theย HTTPย request that our computer sends to the server to fetch a file. It contains some interesting information such as what file you want to retrieve, name of the browser and version, what operating system you are using, what language you prefer to receive the file in, and more.

Step 10: Basic AT Commands – Send and Display Data

exp10_has_4

We can now use the following commands to send some data and display it in our web browserโ€™s window:

AT+CIPSEND=0,5

The โ€œ0โ€ indicates the channel through which the data is going to be transferred; while โ€œ5โ€ represents the number of characters that are going to be sent.

When we hit enter, the symbol โ€œ>โ€ appears. This indicates that we can now type the characters that we want to send to the browser. In this example we chose โ€œhello.โ€

After a couple of seconds we get the response “SEND OK.” This means that the data has been transmitted successfully to the client. However, nothing appears on the web browserโ€™s window yet. This is because it is required to close the channel first in order to display the characters. We use the following command to close the channel:

AT+CIPCLOSE=0

โ€œ0โ€ indicates the channel that is being closed.

Once we hit enter, our message is displayed on the web browserโ€™s window as shown in the image above.

You can refer to the following site to see theย ESP8266 AT Command Set:ย 
http://www.pridopia.co.uk/pi-doc/ESP8266ATCommands…

Step 11: Check that our ESP-01 Receives Data – Mobile Telnet

exp10_has_5

Now we want to check that our ESP-01 module receives data. We will use theย Androidย applicationย โ€œMobile Telnetโ€ย to test this.

  1. Open the Android application and from the menu selectโ€œTelnet Settings.”

Step 12: Check that our ESP-01 Receives Data – Mobile Telnet con.t’

exp10_has_6

Type in theย IP addressย and theย port number.

Click โ€œOKโ€ and from the menu select โ€œConnect.โ€

Step 13: Check that our ESP-01 Receives Data – Mobile Telnet con.t’

exp10_has_7

Type the characters that you want to send and then click the โ€œSendโ€ button.

Step 14: Check that our ESP-01 Receives Data – Mobile Telnet con.t’

exp10_has_8

We get the following response as shown in the image above on theย serial monitor.

The message is successfully received and displayed.

Step 15: Check that our ESP-01 Receives Data – PuTTY

exp10_has_9

Instead ofย Mobile Telnet, you can also useย PuTTYย to check that the ESP-01 is receiving data correctly. You can download PuTTYย here.

If you decide to use PuTTY follow these steps:

  1. Open the program
  2. Select โ€œTelnetโ€ as the connection type
  3. Type the IP address and the port number
  4. Click on โ€œOpen”

Step 16: Check that our ESP-01 Receives Data – PuTTY con.t’

exp10_has_10

  1. Type the characters that you want to send and hit โ€œEnter.โ€

Step 17: Check that our ESP-01 Receives Data – PuTTY con.t’

exp10_has_11

The items used in this experiment
ุงู„ู…ูˆุงุฏ ุงู„ู…ุณุชุฎุฏู…ุฉ ููŠ ุงู„ุชุฌุฑุจุฉ ูŠู…ูƒู†ูƒู… ุงุถุงูุชู‡ุง ุงู„ู‰ ุณู„ุฉ ู…ุดุชุฑูŠุงุชูƒู… ู…ุจุงุดุฑุฉ ู…ู† ู‡ู†ุง

Leave a Reply

Your email address will not be published. Required fields are marked *