members
Basics: Project 021c How to use AT commands - ESP8266 ESP-01 WI FI module
of Acoptex.com in UNO
Basics: Project 021c
Project name: How to use AT commands - ESP8266 ESP-01 WI FI module
Tags: ESP, ESP8266, WI FI module, ESP-01, V090, update firmware, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, FTDI232, FTDI 232, USB to TTL, AT commands, AT communication
Attachments: bareminimumsketch
In this project, you need these parts :
1.Arduino Uno R3 (you can also use the other version of Arduino)
2. ESP8266 ESP-01 WI FI module 1pc
3.Arduino IDE ( you can download it from here )
4.Jumper cables F-M, F-F, M-M
5. Breadboard 1 pc
6. USB to TTL serial converter 1 pc
7. USB mini cable 1 pc (optional)
8. Any voltage regulator LD1117V33, AMS1117 3.3 V or 78R33 (to get 3.3V) or 1 pc
or
or
9. Logical level converter 1 pc (can be resistors - voltage divider)
General
We will learn how to use AT commands of ESP8266 ESP-01 WI FI module.
Understanding the USB to TTL converter
You can read more about them here.
Understanding the ESP8266 WI FI module
The ESP8266 WiFi Module is a self contained SOC (System On a Chip) with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network.
The ESP8266 WiFi Module is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.
Each ESP8266 WiFi Module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino board and get about as much WiFi-ability as a WiFi Shield offers.
The ESP8266 WiFi Module is an extremely cost effective board. This module has a powerful enough on-board processing and storage capability that allows it to be integrated with the sensors and other application specific devices through its GPIOs (General Purpose Input Output) with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, including the front-end module, is designed to occupy minimal PCB area. The ESP8266 supports APSD for VoIP applications and Bluetooth co-existance interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.
In short, the ESP8266 module is a TTL "Serial to Wireless Internet" device, a small microprocessor with built in wi-fi. It is faster than most Arduino boards and has more memory than most Arduino boards and has less pins than an Arduino board.
The ESP8266 comes in a wide variety of versions (as shown in the figure below).
Specification:
- 802.11 b/g/n
- Built-in Tensilica L106 ultra-low-power 32-bit micro MCU, clocked at 80 MHz and 160 MHz, supporting RTOS
- Built-in 10bit high precision ADC
- Built-in TCP/IP stack
- Built-in TR switch, balun, LNA, power amplifier and matching network
- Built-in PLL, voltage regulator, and power management components, +20dBm output power in 802.11b mode
- A-MPDU, A-MSDU aggregation and 0.4s guard interval
- WiFi @ 2.4GHz, supports WPA/WPA2 security mode
- Support AT remote upgrade and cloud OTA upgrade
- Support STA/AP/STA+AP working mode
- Supports Smart Config features (including Android and iOS devices)
- HSPI,UART, I2C, I2S,IR Remote Control,PWM,GPIO
- Deep sleep current is 10uA and shutdown current is less than 5uA
- Wake up, connect and transfer packets within 2ms
- Standby power consumption less than 1.0mW (DTIM3)
- Operating temperature range: -40°C - 125°C
Application:
- create a web server
- send HTTP requests
- control outputs
- read inputs and interrupts
- send emails
- post tweets
HOW DOES IT WORK
The ESP8266 WI FI module can be controlled from your local wifi network or from the internet (after port forwarding set on your router). The ESP8266 communicates with the Arduino through a serial interface. It uses the Arduino’s Rx and Tx pins (digital pins 0 and 1) connected to the ESP8266 ESP-01 module for receiving commands and communicates back. The module features a full TCP/UDP stack support and can be configured as a web server. ESP-01 module powers the onboard ESP8266 through 3.3V. You will have to use a voltage regulator AMS1117 3.3 V or like the 78R33 to step down the 5V from the Arduino to 3.3V or voltage divider (You can find some info here with online calculation sheet) in order to power up the ESP8266.
The ESP8266 does not come with an USB connector on it. You need an additional component for ESP8266 to communicate with the PC or laptop via USB port. It's called USB to TTL serial adapter (for example, USB adapter for ESP8266 ESP-01, FT232RL FTDI USB to TTL Serial Adapter, CP2102 USB to TTL UART converter). So we can either use a USB to TTL serial adapter (converter) or use an Arduino to communicate and upload the code to the ESP8266.
ESP-01 adapters
ESP8266 ESP-01 module
We will use ESP8266 ESP-01 module in this project. It has 2 GPIO pins that can be programmed to turn an LED or a relay ON/OFF through the internet.
The ESP-01 module contains the ESP8266 MCU and a flash memory chip. There are two LED's: a red one which indicates power is connected to the module, and a blue one which indicates data flow, and can also be controlled by user programming. The Wi-Fi antenna is the PCB trace that covers the top of the module; it's called a Meandered Inverted-F Antenna (MIFA,) is surprisingly efficient, and only mildly directional.
There are eight connection pads near the bottom of the module. Usually, two 4-pin male headers are inserted in the rear of the module and soldered on the front. This makes the I/Os accessible, but is not breadboard friendly, and requires flywires from the ESP-01 to a solderless breadboard. This technique works, but it is messy.
ESP8266 ESP-01 module has three operational modes:
1. Access Point (AP) — In AP, the Wi-Fi module acts as a Wi-Fi network, or access point (hence the name). It allows other devices to connect to it. And establishes a two-way communication between the ESP8266 and the device that is connected to it via Wi-Fi.
2. Station (STA) — In STA mode, the ESP-01 can connect to an AP (access point) such as the Wi-Fi network from your house. This allows any device connected to that network to communicate with the module.
3. Both — In this mode ESP-01 act as both an AP as well as in STA mode. Refer to the following site for more ESP8266 AT commands.
ESP8266 ESP-01 module can be set in Flash mode or UART download mode (for uploading new firmware or program) and Boot mode or Flash Boot Mode (normal startup and execution of existing firmware or program).
- Windows(x86, x86-64)
- Linux(x86, x86-64, ARM soft & hard float)
- Solaris(x86, x86-64)
- Mac OS X(x86, x86-64, PPC, PPC64)
- Syntax highlighting LUA and Python code
- Code editor color themes: default, dark, Eclipse, IDEA, Visual Studio
- Undo/Redo editors features
- Code Autocomplete (Ctrl+Space)
- Smart send data to ESP8266 (without dumb send with fixed line delay), check correct answer from ESP8266 after every lines.
- Code snippets
- Detailed logging
Signals and contacts of ESP8266 ESP-01 WI FI module
TXD (TX, TXO or UTXD) - transmit pin. Connected to Arduino Uno pin 1.
RXD (RX, RXI or URXD) - receive pin. Connected to Arduino Uno pin 0.
VCC (3V3 or 3.3V) - power supply pin (3-3.6V). Connected to 3.3V DC 1A and more external power supply. The current required for the ESP-01 during Wi-Fi operation vary from 250mA to 750mA.
RST (RESET) - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.
CH_PD (CHIP_EN or EN) - Chip enable. Keep it on high (3.3V) for normal operation.
GND - Ground. Connected to Arduino board GND pin
GPIO0, GPIO2 (IO0, IO2) - General Purpose Input Output pins. GPIO0 also controls the module mode (programming or normal operation). In our case (normal operation), it shall be connected to 3.3V (high). GPIO2 is not used in this example.
Build the circuit
1. Using ESP01 programmer UART
It is very easy. Simply insert ESP8266 ESP-01 module to ESP01 programmer UART.
2. Using USB to TTL Converter with or without DTR Pin
USB to TTL converter -> ESP8266 ESP-01 module
- GND->GND
- TX->RX
- RX->TX
- VCC 3.3V->3.3V
- VCC 3.3V->EN
3. Using Arduino board
The ESP8266 powered up using a separate 3.3 V power source or a voltage regulator AMS1117 3.3 V or 78R33 or a voltage divider. Note: Do not plug in ESP8266 ESP-01 module directly to 3.3V Arduino Uno board pin as the ESP8266 ESP-01 module may draw more current than the 3.3V regulator on your Arduino can supply so you can damage your Arduino board.
ESP8266 ESP-01 module -> Arduino Uno board
- GND ->GND (through voltage regulator)
- TX -> TX
- RX ->RX (through logic level converter)
- VCC->3.3V (through voltage regulator)
- EN -> 3.3V (through voltage regulator)
Step by Step instruction
1. Using USB to TTL converter with or without DTR Pin or Using ESP01 programmer UART
For using this USB to UART Converter you need a software tool. Most of the development tools like MikroC Pro, Arduino has a UART Tool along with it. You can use different software tools: Terminal, USR-TCP232-Test V1.4, AiThinker_Serial_Tool_V1.2.3, coolterm, sscom3.2 , KiTTY, putty,tera term and so on. We recommend you to use AiThinker_Serial_Tool_V1.2.3 or sscom3.2, as you can save your AT commands and it's very easy to use.
- Do wiring or insert ESP8266 ESP-01 module to ESP01 programmer UART.
- Connect USB to TTL converter (UART converter) or ESP01 programmer UART to your PC USB port.
- Download and open software tool.
- Change the COM port (Serial port). Check in your Device manager -> Ports (COM & LPT) which USB port your UART converter/Arduino Uno board connected to.
- Set the baud rate (can be 115200 or 9600), data bits 8, parity bits none,stop bits one.
- First you need to check if AT commands are working - enter “AT” and press Send button.This would print "OK" which signifies of working connection and operation of the module.
- Enter "AT+GMR" and press Send button. Returns firmware version, for example "AT version:1.2.0.0 (Jul 1 2016 20:04:45) SDK version:1.5.4.1 (39cb9a32) Ai-Thinker Technology Co. Ltd. v1.5.4.1-a Nov 30 2017 15:54:29 OK".
- Enter "AT+CIOBAUD?" and press Send button. Returns the baud rate "+CIOBAUD:115200 OK". If you want to change baud rate enter "AT+CIOBAUD=9600" and press Send buttn. Returns "OK". The baud rate will be changed to 9600 bps.
- Enter "AT+CWMODE?" and press Send button. Returns the mode of operation of ESP8266 ESP-01 module "+CWMODE:2 OK". If 1 - Station mode (client), 2 - AP mode (host), 3 - AP + Station mode. You can change the mode - enter "AT+CWMODE=3" and press Send button. ESP8266 ESP-01 module is in AP + Station mode operational mode now.
-
+CWLAP:(4,"TR-2",-67,"c0:a0:bb:f6:49:f8",11,23,0)OKEnter "AT+CWLAP" and press Send button. It will provide you a list of available wifi access points in your area. For example, returns "+CWLAP:(4,"TR-2",-67,"c0:a0:bb:f6:49:f8",11,23,0) OK".
- Enter "AT+CWJAP="TR-2","password"" and press Send button. Returns "WIFI CONNECTED WIFI GOT IP OK". You joined Access Point TR-2 and can see your module WIFI devices list on your mobile or PC now. Every time you power the ESP8266 ESP-01 module it will try to connect to the same Access Point. You can see if it was successful by checking your router’s DHCP client list. Even if the power is removed, the ESP module will remember the joined AP.
- Enter "AT+CWQAP" and press Send button. Returns "OK". You will quit Access Point.
- Enter "AT+CIFSR" and press Send button. Returns "AT+CIFSR +CIFSR:APIP,"192.168.4.1" +CIFSR:APMAC,"62:01:94:68:fa:9d" +CIFSR:STAIP,"192.168.0.114" +CIFSR:STAMAC,"60:01:94:68:fa:9d" OK". You will get IP Address of the module.
- Enter "AT+CIUPDATE" and press Send button. Returns "+CIPUPDATE:1 +CIPUPDATE:2 +CIPUPDATE:3 +CIPUPDATE:4 OK WIFI DISCONNECT". Firmware upgrade frpm Cloud done. Note that you need to be connected to AP to do that.
- Enter "AT+CIOWRITE=0,0" and press Send button. Returns "OK". It will set the GPIO0 pin to LOW.
- Enter "AT+CIOWRITE=0,1" and press Send button. Returns "OK". It will set the GPIO0 pin to HIGH.
- Enter "AT+CIOWRITE=2,0" and press Send button. Returns "OK". It will set the GPIO2 pin to LOW.
- Enter "AT+CIOWRITE=2,1" and press Send button. Returns "OK". It will set the GPIO2 pin to HIGH.
- Enter "AT+CIOREAD=0" and press Send button. Returns the status of GPIO0 pin, for example "1:HIGH OK".
- Enter "AT+CIOREAD=2" and press Send button. Returns the status of GPIO2 pin, for example "1:LOW OK".
- We need to enable multiple connections before we can configure the ESP8266 ESP-01 module as a server. Enter "AT+CIPMUX=1" and press Send button. Returns "OK". Each number is associated with a type of connection: single = 0, multiple = 1.
- Start the server at port 80. Enter "AT+CIPSERVER=1,80" and press Send button. Returns "OK". 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. Port 80 is the default port for HTTP protocol.
- When we open a web browser and type the IP address of our ESP8266 ESP-01 module (our was 192.168.0.115) we get the following response: "+IPD,0,394:GET / HTTP/1.1 Host: 192.168.0.115 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36 Accept: text/html,application/xhtml+xml, application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 1,CONNECT". 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.
- If we want to send some data and display it in our web browser’s window. Enter "AT+CIPSEND=0,5" and press Send button. 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 type “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. Enter "AT+CIPCLOSE=0" and press Send button.“0” indicates the channel that is being closed. Once we hit enter, our message is displayed on the web browser’s window:
- Enter "AT+RST" and press Send button. It will restart the ESP8266 ES-01 module.
- You can find the list of AT commands here or here.
2. Using ESP8266 config software
- Do wiring.
- Connect USB to TTL converter (UART converter) to your PC USB port.
- Download and open ESP8266 config software. It can be downloaded from here.
- Set baudrate (115200 or 9600 depending on firmware) and COM port (Serial port). Check in your Device manager -> Ports (COM & LPT) which USB port your UART converter/Arduino Uno board connected to.
- Press Connect button.
- Press Serial monitor button for debugging purposes.
- Press FW version button to check the version of firmware and that AT commands are working.
- If AT communication established you can change configuration of ESP8266 ESP-01 module easily now.
3. Using Arduino Uno board
- Do wiring.
- Open Arduino IDE.
- Plug your Adruino Uno board into your PC and select the correct board and com port.
- Verify and upload the bareminimumsketch to your Adruino Uno.
- Open the Serial Monitor at a baud rate of 115200 and choose Both NL & CR (new line and carriage return) from the drop-down menu.
- First you need to check if AT commands are working - enter “AT” and press Send button.This would print "OK" which signifies of working connection and operation of the module.
- Enter "AT+GMR" and press Send button. Returns firmware version, for example "AT version:1.2.0.0 (Jul 1 2016 20:04:45) SDK version:1.5.4.1 (39cb9a32) Ai-Thinker Technology Co. Ltd. v1.5.4.1-a Nov 30 2017 15:54:29 OK".
- Enter "AT+CIOBAUD?" and press Send button. Returns the baud rate "+CIOBAUD:115200 OK". If you want to change baud rate enter "AT+CIOBAUD=9600" and press Send buttn. Returns "OK". The baud rate will be changed to 9600 bps.
- Enter "AT+CWMODE?" and press Send button. Returns the mode of operation of ESP8266 ESP-01 module "+CWMODE:2 OK". If 1 - Station mode (client), 2 - AP mode (host), 3 - AP + Station mode. You can change the mode - enter "AT+CWMODE=3" and press Send button. ESP8266 ESP-01 module is in AP + Station mode operational mode now.
- Enter "AT+CWLAP" and press Send button. It will provide you a list of available wifi access points in your area. For example, returns "+CWLAP:(4,"TR-2",-67,"c0:a0:bb:f6:49:f8",11,23,0) OK".
- Enter "AT+CWJAP="TR-2","password"" and press Send button. Returns "WIFI CONNECTED WIFI GOT IP OK". You joined Access Point TR-2 and can see your module WIFI devices list on your mobile or PC now. Every time you power the ESP8266 ESP-01 module it will try to connect to the same Access Point. You can see if it was successful by checking your router’s DHCP client list. Even if the power is removed, the ESP module will remember the joined AP.
- Enter "AT+CWQAP" and press Send button. Returns "OK". You will quit Access Point.
- Enter "AT+CIFSR" and press Send button. Returns "AT+CIFSR +CIFSR:APIP,"192.168.4.1" +CIFSR:APMAC,"62:01:94:68:fa:9d" +CIFSR:STAIP,"192.168.0.114" +CIFSR:STAMAC,"60:01:94:68:fa:9d" OK". You will get IP Address of the module.
- Enter "AT+CIUPDATE" and press Send button. Returns "+CIPUPDATE:1 +CIPUPDATE:2 +CIPUPDATE:3 +CIPUPDATE:4 OK WIFI DISCONNECT". Firmware upgrade frpm Cloud done. Note that you need to be connected to AP to do that.
- Enter "AT+CIOWRITE=0,0" and press Send button. Returns "OK". It will set the GPIO0 pin to LOW.
- Enter "AT+CIOWRITE=0,1" and press Send button. Returns "OK". It will set the GPIO0 pin to HIGH.
- Enter "AT+CIOWRITE=2,0" and press Send button. Returns "OK". It will set the GPIO2 pin to LOW.
- Enter "AT+CIOWRITE=2,1" and press Send button. Returns "OK". It will set the GPIO2 pin to HIGH.
- Enter "AT+CIOREAD=0" and press Send button. Returns the status of GPIO0 pin, for example "1:HIGH OK".
- Enter "AT+CIOREAD=2" and press Send button. Returns the status of GPIO2 pin, for example "1:LOW OK".
- We need to enable multiple connections before we can configure the ESP8266 ESP-01 module as a server. Enter "AT+CIPMUX=1" and press Send button. Returns "OK". Each number is associated with a type of connection: single = 0, multiple = 1.
- Start the server at port 80. Enter "AT+CIPSERVER=1,80" and press Send button. Returns "OK". 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. Port 80 is the default port for HTTP protocol.
- When we open a web browser and type the IP address of our ESP8266 ESP-01 module (our was 192.168.0.115) we get the following response: "+IPD,0,394:GET / HTTP/1.1 Host: 192.168.0.115 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36 Accept: text/html,application/xhtml+xml, application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 1,CONNECT". 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.
- If we want to send some data and display it in our web browser’s window. Enter "AT+CIPSEND=0,5" and press Send button. 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 type “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. Enter "AT+CIPCLOSE=0" and press Send button.“0” indicates the channel that is being closed. Once we hit enter, our message is displayed on the web browser’s window:
- Enter "AT+RST" and press Send button. It will restart the ESP8266 ES-01 module.
- You can find the list of AT commands here or here.
SocketTest
A java tool for socket testing. It can create both TCP and UDP client or server. It can be used to test any server or client that uses TCP or UDP protocol to communicate.
You can donload it here.
Summary
We have learnt how to use AT commands of ESP8266 ESP-01 WI FI module.
Library
- No libraries required for this project.
Sketch
- You can find it on the begining of this project
Other projects of Acoptex.com










Viewed: 15005 times