Using AT commands on the ESP8266 | Circuitrocks (2024)

In this tutorial, we are going to explore the pre-installed AT firmware inside the ESP8266.

Table Of Contents

  1. The AT Firmware
    • Sending AT commands using Arduino UNO
      • Fundamental AT commands
    • Using the Arduino to program the ESP-01
    • Using the NodeMCU
  2. Code
  3. Code Explanation
  4. Demonstration

The AT Firmware

The AT firmware is a pre-installed software in the ESP8266’s ROM (Read-Only Memory). It uses AT commands which are based on the Hayes Command Set. The Hayes Commands Set are commands for telecommunication operations. For instance, dialing a number or making a call.

Further, AT commands are often used for rapid testing of the ESP8266. They can either be sent using the serial monitor or via the ESP8266 sketch.

Sending AT commands using Arduino UNO

Parts you need:

  • Arduino UNO
  • ESP8266-01 module
  • 1 x 1k? resistor
  • 1 x 2.2k? resistor
  • 1 x 10k? resistor
  • Jumper wires
Using AT commands on the ESP8266 | Circuitrocks (2)

First, create a voltage divider using a 1k? and 2.2k? resistor. The default logic level of an Arduino is 5V. Although the ESP8266-01’s TX and RX pin are 5V tolerant, it still gets damage in the long run. To prevent this, we use a logic level converter or a voltage divider to reduce the signal to 3.3V. Next, initialize the ESP-01. Connect the EN/CH-PD (Enable) pin to the 3.3V supply. Use a 10k pull-up resistor.

In the Arduino IDE, choose Generic ESP8266 Module as your board of choice.

Using AT commands on the ESP8266 | Circuitrocks (3)

Open the serial monitor. Set the baud rate to 115200 and enter the desired AT command.

Fundamental AT commands

AT+CWMODE

As mentioned in the previous article, the ESP8266 can be set to 3 different modes. To set the module as a station, enter AT+CWMODE=1. To set as an access point, enter AT+CWMODE=2. As both, enter AT+CWMODE=3. To check the current mode the ESP8266 is in, use AT+CWMODE?.

AT+CWLAP

See the available WiFi networks in your location.

AT+CWJAP="WiFi network name","Wifi network password"

Connect to a WiFi network.

AT+CIFSR

See ESP-01’s MAC and IP address.

AT+CIPMUX

Enable multiple connections using AT+CIPMUX=1. Disable it by using AT+CIPMUX=0.

AT+CIPSERVER

Start a server using AT+CIPSERVER=1,80. The first number indicates status. A value of 0 means closed while 1 means opened. The second number tells the port number.

AT+CIPSEND

Sends data to your server. To demonstrate, suppose you want to send 5 characters to channel 0. You should enter AT+CIPSEND=0,5 in the serial monitor.

The commands should look like this in the serial monitor.

Using AT commands on the ESP8266 | Circuitrocks (4)

They are certainly easier to implement in the serial monitor than your usual Arduino framework.

See all 88 AT commands here.

Using AT commands on the ESP8266 | Circuitrocks (5)

But they have their limits. Let’s use them on actual Arduino code in the next section.

Using the Arduino to program the ESP-01

Parts you need:

  • Arduino UNO
  • ESP8266-01 module
  • 1 x 1k? resistor
  • 1 x 2.2k? resistor
  • 1 x 10k? resistor
  • Jumper wires
Using AT commands on the ESP8266 | Circuitrocks (6)

First, to set the Arduino board as an ESP programmer, connect the RESET pin to GROUND. Then, create a voltage divider just like before. Next, initialize the ESP-01. Connect the EN/CH-PD (Enable) pin to the 3.3V supply. Use a 10k pull-up resistor as well. Finally. connect the pin 0 to GND to start program mode.

In the Arduino IDE, choose Generic ESP8266 Module.

Using AT commands on the ESP8266 | Circuitrocks (7)

Using the NodeMCU

Parts you need:

  • NodeMCU development board
Using AT commands on the ESP8266 | Circuitrocks (8)

Plug and play! All you need to do is set the board in the Arduino IDE to NodeMCU.

Using AT commands on the ESP8266 | Circuitrocks (9)

Code

#include <SoftwareSerial.h> SoftwareSerial esp8266(2,3); #define serialCommunicationSpeed 115200 #define DEBUG true void setup(){ Serial.begin(serialCommunicationSpeed); esp8266.begin(serialCommunicationSpeed); InitWifiModule(); }void loop() { if(esp8266.available()) { if(esp8266.find("+IPD,")) { delay(1000); int connectionId = esp8266.read()-48; String webpage = "<h1>Hello World!</h1>"; String cipSend = "AT+CIPSEND="; cipSend += connectionId; cipSend += ","; cipSend +=webpage.length(); cipSend +="\r\n"; sendData(cipSend,1000,DEBUG); sendData(webpage,1000,DEBUG); String closeCommand = "AT+CIPCLOSE="; closeCommand+=connectionId; // append connection id closeCommand+="\r\n"; sendData(closeCommand,3000,DEBUG); } }}String sendData(String command, const int timeout, boolean debug){ String response = ""; esp8266.print(command); long int time = millis(); while( (time+timeout) > millis()) { while(esp8266.available()) { char c = esp8266.read(); response+=c; } } if(debug) { Serial.print(response); } return response; }void InitWifiModule(){ sendData("AT+RST\r\n", 2000, DEBUG); sendData("AT+CWJAP=\"SSID\",\"Password\"\r\n", 2000, DEBUG); delay (3000); sendData("AT+CWMODE=1\r\n", 1500, DEBUG); delay (1500); sendData("AT+CIFSR\r\n", 1500, DEBUG); delay (1500); sendData("AT+CIPMUX=1\r\n", 1500, DEBUG); delay (1500); sendData("AT+CIPSERVER=1,80\r\n", 1500, DEBUG); }

Code Explanation

First, initialize a SoftwareSerial communication line. The default pins for serial communication, 0 and 1, tend to get busy when the serial monitor is running. To avoid having corrupted data, we transfer serial communication with the ESP-01 to pins 2 and 3.

#include <SoftwareSerial.h> SoftwareSerial esp8266(2,3); 

Then, in the setup section, initialize the serial monitor and serial communications with your ESP8266’s baud rate. The default baud rate is 115200. Using InitWifiModule(), connect to your WiFi network.

void setup(){ Serial.begin(serialCommunicationSpeed); esp8266.begin(serialCommunicationSpeed); InitWifiModule(); }

Then, in the loop section, we store AT commands in strings so that we can send them via Software Serial. We use the sendData() to send them.

void loop() { if(esp8266.available()) { if(esp8266.find("+IPD,")) { delay(1000); int connectionId = esp8266.read()-48; String webpage = "<h1>Hello World!</h1>"; String cipSend = "AT+CIPSEND="; cipSend += connectionId; cipSend += ","; cipSend +=webpage.length(); cipSend +="\r\n"; sendData(cipSend,1000,DEBUG); sendData(webpage,1000,DEBUG); String closeCommand = "AT+CIPCLOSE="; closeCommand+=connectionId; closeCommand+="\r\n"; sendData(closeCommand,3000,DEBUG); } }}

Demonstration

Upload the sketch to your ESP8266. Next, check for the serial monitor. It should display the IP address of your local webserver. Enter the IP address to your favorite browser.

Using AT commands on the ESP8266 | Circuitrocks (10)
Using AT commands on the ESP8266 | Circuitrocks (2024)
Top Articles
What Are Fat Bombs? Should You Eat These Keto Snacks?
How to Pay Yourself as a Business Owner
Bubble Guppies Who's Gonna Play The Big Bad Wolf Dailymotion
417-990-0201
Kreme Delite Menu
Pnct Terminal Camera
Air Canada bullish about its prospects as recovery gains steam
Wannaseemypixels
Coffman Memorial Union | U of M Bookstores
Kansas Craigslist Free Stuff
San Diego Terminal 2 Parking Promo Code
Bhad Bhabie Shares Footage Of Her Child's Father Beating Her Up, Wants Him To 'Get Help'
biBERK Business Insurance Provides Essential Insights on Liquor Store Risk Management and Insurance Considerations
Revitalising marine ecosystems: D-Shape’s innovative 3D-printed reef restoration solution - StartmeupHK
Best Restaurants Ventnor
The Weather Channel Facebook
Craigslist Pets Longview Tx
O'reilly's Auto Parts Closest To My Location
Best Food Near Detroit Airport
Labor Gigs On Craigslist
Most McDonald's by Country 2024
Becu Turbotax Discount Code
Telegram Scat
Canvas Nthurston
Craigslist In Flagstaff
DBZ Dokkan Battle Full-Power Tier List [All Cards Ranked]
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Northeastern Nupath
Project Reeducation Gamcore
fft - Fast Fourier transform
Dashboard Unt
Craigslist Brandon Vt
Kuttymovies. Com
Kristy Ann Spillane
Imagetrend Elite Delaware
Sam's Club Near Wisconsin Dells
Publix Daily Soup Menu
Urban Blight Crossword Clue
Orange Pill 44 291
Puretalkusa.com/Amac
Watchseries To New Domain
Emerge Ortho Kronos
How To Paint Dinos In Ark
Dcilottery Login
Ezpawn Online Payment
Unitedhealthcare Community Plan Eye Doctors
Sky Dental Cartersville
Pas Bcbs Prefix
Puss In Boots: The Last Wish Showtimes Near Valdosta Cinemas
Publix Store 840
Helpers Needed At Once Bug Fables
Naughty Natt Farting
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 6585

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.