Handson Technology ESP8266 WiFi User manual

1
www.handsontec.com
ESP8266 WiFi
The ESP8266 is the name of a micro controller designed by Espressif Systems. The
ESP8266 itself is a self-contained WiFi networking solution offering as a bridge from
existing micro controller to WiFi and is also capable of running self-contained applications.
This module comes with a built in USB connector and a rich assortment of pin-outs. With a
micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any
trouble, just like Arduino. It is also immediately breadboard friendly.

2
www.handsontec.com
Table ofContents
1.
Specification..........................................................................................................................................3
2.
Pin Definition .........................................................................................................................................3
3.
Using ArduinoIDE .................................................................................................................................3
Install the ArduinoIDE 1.6.4or greater..................................................................................................4
Installthe ESP8266Board Package................................................................................................4
SetupESP8266Support.................................................................................................................5
Blink Test........................................................................................................................................7
Connecting viaWiFi........................................................................................................................9
4.
FlashingNodeMCUFirmwareon theESP8266usingWindows............................................................12
PartsRequired...................................................................................................................................12
Pin Assignment..................................................................................................................................12
Wiring................................................................................................................................................13
Downloading NodeMCU FlasherforWindows ....................................................................................13
Flashing your ESP8266usingWindows..............................................................................................13
5.
Getting Started with the ESPlorerIDE ..................................................................................................15
Installing ESPlorer .............................................................................................................................15
Schematics........................................................................................................................................18
Writing YourLua Script.......................................................................................................................18
6.
NodeMCU GPIOfor Lua..........................................................................................................................22
7.
WebResources.......................................................................................................................................22

3
www.handsontec.com
1.
Specification:
•
Voltage:3.3V.
•
Wi-Fi Direct (P2P), soft-AP.
•
Current consumption: 10uA~170mA.
•
Flash memory attachable: 16MB max (512K normal).
•
Integrated TCP/IP protocol stack.
•
Processor: Tensilica L106 32-bit.
•
Processor speed: 80~160MHz.
•
RAM: 32K + 80K.
•
GPIOs: 17 (multiplexed with other functions).
•
Analog to Digital: 1 input with 1024 step resolution.
•+19.5dBm output power in 802.11b mode
•
802.11 support: b/g/n.
•
Maximum concurrent TCP connections: 5.
2.
Pin Definition:
3.
Using ArduinoIDE

4
www.handsontec.com
T
h
e
m
o
s
t
b
a
s
i
c
w
a
y
t
o
u
s
e
t
h
e
E
S
P
8266
m
odu
l
e
i
s
t
o
u
s
e
s
e
r
i
a
l
c
o
mm
a
nd
s
,
a
s
t
h
e
c
h
i
p
i
s
b
a
s
i
c
a
ll
y
a
W
i
F
i
/
S
e
r
i
a
l
transceiver. However, this is not convenient. What we recommend is using the very cool Arduino ESP8266 project,
which is a modified version of the Arduino IDE that you need to install on your computer. This makes it very
convenienttousetheESP8266chipaswewillbeusingthewell-knownArduinoIDE.Followingthebelowstepto
installESP8266librarytowork inArduinoIDEenvironment.
Install the Arduino IDE 1.6.4 or greater
Download Arduino IDE from Arduino.cc (1.6.4 or greater) - don't use 1.6.2 or lower version! You can use your
existing IDEif youhave alreadyinstalled it.
You can also try downloading the ready-to-go package from the ESP8266-Arduino project, if the proxy is giving you
problems.
Install the ESP8266 Board Package
En
t
e
r
h
tt
p:
//
ar
du
i
no
.e
s
p8
266
.c
o
m
/
s
t
abl
e
/
pack
age_
e
s
p
8266
c
o
m_
i
n
de
x
.j
s
on
i
n
to
Addi
t
i
on
al
B
o
ard
M
a
na
g
e
r
U
R
L
s
field in the Arduino v1.6.4+ preferences.
Click ‘File’ -> ‘Preferences’ to access this panel.
Next, use the Board manager to install the ESP8266 package.

5
www.handsontec.com
Click ‘Tools’ -> ‘Board:’ -> ‘Board Manager…’ to access this panel.
Scroll down to ‘esp8266 by ESP8266 Community ’and click “Install” button to install the ESP8266 library package.
Onceinstallationcompleted,closeandre-openArduinoIDEforESP8266librarytotakeeffect.
Setup ESP8266Support
Whenyou'verestartedArduinoIDE,select‘GenericESP8266Module’fromthe‘Tools’->‘Board:’dropdownmenu.
Select 80 MHz as the CPU frequency (you can try 160 MHz overclock later)

void setup() {
pinMode(5, OUTPUT); // GPIO05, Digital Pin D1
}
void loop() {
digitalWrite(5, HIGH);
delay(900);
digitalWrite(5, LOW);
delay(500);
}
7
www.handsontec.com
Find out which Com Port is assign for CH340
SelectthecorrectComPortasindicatedon‘Device Manager”
Note: if this is your first time using CH340 “USB-to-Serial ”interface, please install the driver first before proceed
theaboveComPortsetting.TheCH340drivercanbedownloadfromthebelowsite:
h
tt
ps
:
//
gi
t
hu
b.c
o
m
/
no
de
m
c
u
/
no
de
m
c
u
-
d
e
v
k
i
t/tr
ee
/
m
a
s
te
r
/D
r
i
v
e
r
s
Blink Test
We'll begin with the simple blink test.
Enter this into the sketch window (and save since you'll have to). Connect a LED as shown in Figure3-1.
Nowyou'llneedtoputtheboardintobootloadmode.You'llhavetodothisbeforeeachupload.Thereisnotimeout
for bootloadmode, soyou don't haveto rush!
•Hold down the ‘Flash’ button.
•While holding down ‘Flash’, press the ‘RST’ button.
•Release‘RST’, then release‘Flash’

// key in your own SSID
// key in your own WiFi access point
const char* password = "abc1234";
password
= "handson";
const char* ssid
/*
* Simple HTTP get webclient test
*/
#include <ESP8266WiFi.h>
Figure 3.2: Uploading the sketch to ESP8266 NodeMCU module.
The sketch will start immediately - you'll see the LED blinking. Hooray!
Connecting via WiFi
OKonce you'vegotthe LEDblinking,let’s go straighttothe fun part, connecting toa webserver. Create anew sketch
with thiscode:
Don’t forget to update:
constchar*ssid = "yourssid";
const char* password = "yourpassword";
toyourWiFiaccesspointandpassword,thenuploadthesameway:getintobootloadmode,thenuploadcodevia
IDE.
9
www.handsontec.com

const char* host = "www.handsontec.com";
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/projects/index.html";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
10
www.handsontec.com

4.
Flashing NodeMCU Firmware on the ESP8266 using Windows
Why flashing your ESP8266 module with NodeMCU?
NodeMCU isafirmwarethatallowsyou toprogram the ESP8266 modules with LUA script. And you’ll finditvery
similartothewayyouprogramyourArduino.WithjustafewlinesofcodeyoucanestablishaWiFiconnection,
controltheESP8266GPIOs,turningyourESP8266intoawebserverandalotmore.
InthistutorialwearegoingtouseanotherESP8266modulewithpinheaderadapterboardwhichisbreadboard
friendly.
ESP8266 Module Breadboard Friendly with Header Connector
Parts Required:
•
ESP8266 Module Breadboard Friendly
•
PL2303HX USB-UART Converter Cable
•Some Male-to-Female JumperWires
Pin Assignment:
12
www.handsontec.com

Wiring:
ESP8266 Pin
Description
CH_PD
Pull high, connect to Vcc +3.3V
Vcc
Power Supply +3.3V
TXD
Connect to RXD (white) of PL2303HX USB-Serial converter cable
RXD
ConnecttoTXD(Green)ofPL2303HXUSB-Serialconvertercable
GPIO0
Pull low, connect to GND pin
GND
Power Supply ground
Downloading NodeMCU Flasher for Windows
Afterwiring your circuit, you have todownload the NodeMCU flasher. This isa .exe file that you can download using
one of the following links:
•
Win32 Windows Flasher
•
Win64 Windows Flasher
You can find all the information about NodeMCU flasher here.
Flashing your ESP8266 using Windows
Open the flasher that you just downloaded and a window should appear (as shown in the following figure).
13
www.handsontec.com

Pressthebutton“Flash”anditshouldstarttheflashingprocessimmediately,showingtheModuleMACaddressif
successfulconnected.
After finishing this flashing process, it should appear a green circle with a check icon at lower left corner.
Your ESP8266 module is now loaded with NodeMCU firmware.
14
www.handsontec.com

5.
Getting Started with the ESPlorer IDE
ESPlorer is an IDE (Integrated Development Environment) for ESP8266 devices. It’s a multi platform IDE, can be
used in any OS environment, this simply means that it runs on Windows, Mac OS X or Linux.
Supported platforms:
•Windows(x86, x86-64)
•Linux(x86, x86-64, ARM soft & hard float)
•Solaris(x86, x86-64)
•Mac OS X(x86, x86-64, PPC, PPC64)
This software allows you to establish a serial communications with your ESP8266 module, send commands, and
upload code and much more.
Requirements:
•YouneedtohaveJAVAinstalledinyourcomputer.If youdon’t have,gotothis
website:http://java.com/download,downloadand install thelatestversion.Itrequires JAVA(SEversion7
and above)installed.
•
Inorderto complete the sample project presented in this Guide youneedtoflash your ESP8266with
NodeMCUfirmware.Refertochapter-4inthisguideonhowtoflashtheNodeMCUfirmware.
Main Resources:
•ESPlorer Homepage:http://esp8266.ru/esplorer/
•
G
i
t
H
ub
R
e
po
s
i
t
o
r
y
:
h
tt
p
s
:
//
g
i
t
hub
.
c
o
m
/
4
r
e
f
r
0
n
t
/
E
S
P
l
o
r
e
r
Installing ESPlorer
Now let’s download the ESPlorer IDE, visit the following URL: http://esp8266.ru/esplorer/#download
Grabthe folder that you just downloaded. Itshouldbenamed“ESPlorer.zip” andunzipit.Insidethatfolder you
should seethe following files:
Execute the “ESPlorer.jar” file and the ESPlorer IDE should open after a few seconds (the “ESPlorer.jar” file is what
youneedto openeverytime youwantto workwiththe ESPlorerIDE).
15
www.handsontec.com

Note:Ifyou’re onMacOSXorLinuxyousimplyusethiscommandlineinyourterminaltoruntheESPlorer:sudo
java –jarESPlorer.jar.
When the ESPlorer first opens, that’s what you should see:
Here’s a rundown of the features the ESPlorer IDE includes:
•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.
•And a lot more…
The ESPlorer IDE has a couple of main sections, let’s break it down each one.
In the top left corner you can see all the regular options that you find in any software. Create a New file, Open a new
file, Save file, Save file as, Undo, Redo, etc.
16
www.handsontec.com

In the top right corner you have all the options you need to establish a serial communication (you’re going to learn
how to use them later in this Guide).
This next screenshot shows your Code Window, that’s where you write your scripts (your scripts are highlighted with
your code syntax).
Below the Code Window, you have 12 buttons that offer you all the functions you could possible need to interact with
your ESP8266. Here’s the ones you’ll use most: “Save to ESP” and “Send to ESP”.
This screenshot shows the Output Window which tells you exactly what’s going on in your ESP8266. You can see
errors and use prints in your code to debug your projects.
17
www.handsontec.com

Schematics
To upload code to your ESP8266, you should connect your ESP8266 to your PL2303HX USB-UART Programming Cable
like the figurebelow:
Writing Your Lua Script
Below is your script to blink an LED.
Right now you don’t need to worry how this code works, but how you can upload it to your ESP8266.
lighton=0
pin=4
gpio.mode(pin,gpio.OUTPUT)
tmr.alarm(1,2000,1,function()
if lighton==0 then
lighton=1
gpio.write(pin,gpio.HIGH)
else
lighton=0
gpio.write(pin,gpio.LOW)
end
end)
18
www.handsontec.com

Having your ESP8266+PL2303HX Programmer connected to your computer, go to the ESPlorer IDE:
Look at the top right corner of your ESPlorer IDE and follow these instructions:
1.
Press the Refreshbutton.
2.
Selectthe COMport for your FTDI programmer.
3.
Select yourbaudrate.
4.
Click Open.
Then in the top left corner of your ESPlorer IDE, follow these instructions:
1.
SelectNodeMCU
2.
SelectScripts
3.
Create a newfilled called “init.lua”
19
www.handsontec.com

Copy your Lua script to the code window (as you can see in the Figure below):
The next step is to save your code to your ESP8266!
At the left bottom corner click the button “Save to ESP”.
In your output window, it should start showing exactly which commands are being sent to your ESP8266 and it should
look similar to the Figure below.
20
www.handsontec.com
Table of contents
Other Handson Technology Control Unit manuals