You are on page 1of 6

ESP8266 Basic

From ElectroDragon
Share
Contents
1 Module Pin Description ESP-01
2 Module wiring
3 Setup Check list
4 Use Guide of AT Commands
5 Arduino Control Demo Code
6 Note

Module Pin Description ESP-01


Normal mode: Normal boot from flash, normal working mode
Flash mode: Firmware flash mode

Working Flash
Pin Description
Mode Mode
VCC, power supply, better use a standalone, and share
GND* ground with uart port
TXD,
uart interface
RXD**
RST Restart on low TTL
CH_PD 1 1 Chip select, constant High TTL for both mode
GPIO 15 0 0 Low TTL for both mode on boot , N/A for ESP-01
GPIO0 1 (optionally) 0 Switch Wroking/Flash Mode
GPIO 2 -
(cancelled on latest) constants on to show the power
Red LEDs
status
Blue
blink when data come through
LEDs

Module wiring
Pin definition ESP-01 use with CH340 battery with esp12
USB-TTL

Use FT232RL can supply enough power, must be genius IC of course


Swap the uart pins if no data show up on the monitor
There are two leds on the board, one is power led (RED), another one is status LED(BLUE),
when power up, pwr led keeps on and status led will blink once.
baud rate may work at 9600 (seems the latest correct one), 115200 or 57600

Setup Check list


Check list Description
if your devices (e.g. your phone) can find a wifi spot named like "ESP_98529F",
Check default
"AI-...." or similar, the later number part is the mac ID, if you can see this wifi
wifi status
spot, it means your module boot up successfully
check LED blue led will blink once on boot up, serial data output "ESP Ready", Tick "new
status and line" option on USB-TTL serial port monitor tool, Try baudrate 9600 or 115200
wiring default firmware use these two
Check power
use shared GND will standalone power supply
supply
Check IO15
connect GPIO15 to GND on boot if you are using the SMD model
status

"ESP_990B15" is the See the final "ready"


module wifi spot, when boot up
password successfully
0123456789

Use power source that can provide sufficient current, better not using power from USB-TTL
module
Module will automatically disconnect "unlink" TCP/UDP when no data go through
Wifi password length must be more than 8 bytes
Use Guide of AT Commands
At
Header text Header text
Commands
restart the module, received some
Reset AT+RST
strange data, and "ready"
change the working mode to 3,
Set Work AP+STA, only use the most
AT+CWMODE=3
Mode AP+STA versatile mode 3, AT+RST may be
necessary when this is done
Join Network AT+CWLAP search available wifi spot
join my mercury router spot, e.g.
AT+CWJAP=TP-
LINK_4226,1234567890,
Join Network AT+CWJAP=you ssid, password
password length must be correct,
remove all the empty space in the
command
check if connected successfully,
Join Network AT+CWJAP? or use AT+CWJAP=?, or use
AT+CIFSR to find your ip address
check current version, output
AT+GMR AT version:0.30.0.0(Jul 3
2015 19:35:49) / SDK
Cloud Update AT+GMR version:1.2.0 / Ai-Thinker
Technology Co.,Ltd. /
Build:1.2.0.A Aug 7 2015 17:21:44
/ OK
get reply +CIPUPDATE:1,
Cloud Update AT+CIUPDATE +CIPUPDATE:2, +CIPUPDATE:3,
+CIPUPDATE:4, OK
TCP Client AT+CIPMUX=1 turn on multiple connection
connect to remote TCP server
TCP Client AT+CIPSTART=4,"TCP","192,168.1.104",9999
192.168.1.104 (the PC)
optionally enter into data
TCP Client AT+CIPMODE=1
transmission mode
send data via channel 4, 5 bytes
length (see socket test result
TCP Client AT+CIPSEND=4,5 below, only "elect" received), link
will be "unlink" when no data go
through
setup TCP server, on port 9999, 1
TCP Server AT+CIPSERVER=1,9999
means enable
TCP Server AT+CIFSR check module IP address

Test, PC as a TCP client connect to module using socket test, send data
Socket test running result, In the sockettest, do not tick the "secure" in TCP client, it causes
unstable
CIPSTART CIPSEND send data Receive data
"Electrodragon"

Arduino Control Demo Code


In this case, the wifi module still connect to hardware serial (software serial port can not
higher than 19200 baud rate), and another software serial port should be created on arduino
and print out via another serial port
So the connection should be

Wifi's uart to arduino hardware uart;


arduino's sotware UART to another serial port device, for example like FTDI basic, CP2102 breakout, etc, and this

change the SSID and password in code for your wifi router

#include <SoftwareSerial.h>
#define SSID "xxxxxxxx"
#define PASS "xxxxxxxx"
#define DST_IP "220.181.111.85" //baidu.com
SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.setTimeout(5000);
dbgSerial.begin(9600); //can't be faster than 19200 for softserial
dbgSerial.println("ESP8266 Demo");
//test if the module is ready
Serial.println("AT+RST");
delay(1000);
if (Serial.find("ready"))
{
dbgSerial.println("Module is ready");
}
else
{
dbgSerial.println("Module have no response.");
while (1);
}
delay(1000);
//connect to the wifi
boolean connected = false;
for (int i = 0; i < 5; i++)
{
if (connectWiFi())
{
connected = true;
break;
}
}
if (!connected) {
while (1);
}
delay(5000);
//print the ip addr
/*Serial.println("AT+CIFSR");
dbgSerial.println("ip address:");
while (Serial.available())
dbgSerial.write(Serial.read());*/
//set the single connection mode
Serial.println("AT+CIPMUX=0");
}
void loop()
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
Serial.println(cmd);
dbgSerial.println(cmd);
if (Serial.find("Error")) return;
cmd = "GET / HTTP/1.0\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if (Serial.find(">"))
{
dbgSerial.print(">");
} else
{
Serial.println("AT+CIPCLOSE");
dbgSerial.println("connect timeout");
delay(1000);
return;
}
Serial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
dbgSerial.write(c);
if (c == '\r') dbgSerial.print('\n');
}
dbgSerial.println("====");
delay(1000);
}
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
dbgSerial.println(cmd);
Serial.println(cmd);
delay(2000);
if (Serial.find("OK"))
{
dbgSerial.println("OK, Connected to WiFi.");
return true;
} else
{
dbgSerial.println("Can not connect to the WiFi.");
return false;
}
}

Note
Avoid to use GPIO4 (D2) and GPIO5 (D1) in nodemcu, it seems switched: GPIO5 =D2 and
GPIO4=D1
Retrieved from "http://www.electrodragon.com/w/index.php?title=ESP8266_Basic&oldid=12515"

Category: ESP8266

This page was last modified on 1 December 2016, at 06:42.

You might also like