You are on page 1of 7

11/28/2015

ESP8266QuickStartGuide

ESP8266QuickStart
PeterJennings

Home
Paragliding
Travel
Photos
Software
HamRadio
History
Contact

ESP8266Projects
QuickStartGuide
LuaLoaderforWindows
ESP8266forDummies
ESP8266ControlledOutlet
WiFiHotspotFinder
WifiConnectedButton
AskGoogleforthetime
ACPowerMonitor
RainGaugeMonitor

MSP430Projects
GoProController
KISSThermostat
TemperatureLogger

HamRadioCalls
C31LJ
VE3SUN
AB6WM
LZ/G0RZJ
HB0/G0RZJ
CO/VE3SUN
VE3GEJ

Projects
GoProCamera
InternationalBeaconProject
HamLocatorMap
BeaconMonitor
KiteAerialPhotography
IP9100A
CottageCam

http://benlo.com/esp8266/esp8266QuickStart.html

1/7

11/28/2015

ESP8266QuickStartGuide

Downloads
DXMonitor
DOSBeam1.11
HamPopTSR
Qrate

Travels
ParaglidingNomadness
GreenlandandArctic
Colombia
Morocco
Turkey
Pyrenees
Cuba
Postcards

ForSale
ESP8266boards
ESP12boards
ESP01boards
NodeMCUdevelopmentboards

Associations
NCDXF
URA
SLVARC
SCCARC
IARU
RAC
NCCC
CCO

FAQ
WhoisPeterJennings?
WhereisPeter?

ConnectWithMe
Twitter
Facebook
LinkedIn

ESP8266QuickStart
ThispageismeanttobeaquickintroductiontotheESP8266forthosewhoareconfusedbyalloftheinformationavailableonthevariousblogs
andforumswhojustwanttotryoutthisexcitingboardintheshortestpossibletime.ThisguideisforWindowsuserswhowanttousethe
NodeMCUenvironment.
Notcountingwaitingforhardwaretoshiptoyou(110days),youshouldbeabletouseyourESP8266forsomethingusefulinlessthananhour.
Ready?

WhatdoIneedtobuy?
YouwillneedanESP8266developmentboard.ThereareseveralESP8266boardsavailable,usuallynumberedESP01throughESP12.Check
thepinsoftheactualboardyouorderwiththeinformationfromyoursourceastherapiddevelopmentoftheseproductshasledtoconfusionand
duplicationofboardidentificationnumbers.
Thepricesvaryfromaround$2forasimpleESP01to$15foracompleteboardwithUSBtoserialand3.3voltregulator.TheESP01isa
simpleboardtostartwith.TheESP12ispopularbecauseofitssizeandthenumberofpinsbroughttothesideoftheboard.Recently,more
developmentboardshavebecomeavailablewithadditionalsensors,relays,LEDsandvoltageregulatorsontheboard.
http://benlo.com/esp8266/esp8266QuickStart.html

2/7

11/28/2015

ESP8266QuickStartGuide

A3voltpowersupply.TheESP8266runsonanythingfrom2.8to3.5volts,soacoupleofAAbatterieswillwork.Mostofususea3.3volt
regulatedpowersource.Maximumcurrentdrawis300mA,souseasupplythatcansupply500mAtobesafe.Moreisbetter.Aweakorpoor
qualitysupplywillcausetheboardtoresetunexpectedlyandmakedebuggingdifficult.TheNodeMCUDevelopmentBoardhasaUSBto3.3V
powersupplyontheboard.
AUSBtoserialadapter.Thisshouldbea3.3voltcompatiblemodel.Itispossibletolevelconvertifyoualreadyhavea5voltadapter.The
NodeMCUDevelopmentBoardhastheUSBtoserialinterfaceontheboard.Whenyoureceiveyouradapter,verifythattheactualvoltage
outputis3.3voltsassomecheapadaptershavebeenfoundtobemislabelled.Anyofthefollowingshouldwork:FTDi,CH340,FT232RL.

WhatdoIneedtodownload?
TheESP8266boardyouboughtmayhaveoneofmanydifferentfirmwareversionsonit.ManycomewithATfirmwareforserial
communications.Somecomewithnouserfirmwareatall.IrecommendtheNodeMCULuafirmwareasastartingpointbecauseitgivesyouan
interactiveprogramminglanguagewhichallowsyoutoexperimentandbuildsimpleworkingprogramswithoutalotofeffort.Ifyouarenot
familiarwithLua,youwillfindthatitisnothardtolearn,atleastforthesimpletasksneededtogetstarted.
ThetoolyouwillusetoflashtheNodeMCUfirmwareonyourESP8266boardisthenodemcuflasher.Itisopensourceongithub.Gotothe
nodemcuflasherpageandchooseWin32orWin64dependingonyourcomputersystem.ClickonESP8266Flasher.exeandthenrightclickon
ViewRawandSaveLinkAs...todownloadtheapplicationtoyourPC.Orusethedirectlinksbelow:
ESP8266Flasher.exeforWin32
ESP8266Flasher.exeforWin64

WhatdoIhavetoconnect?
TheactualconnectionswilldependontheboardyouhaveandtheUSBtoserialadapteryouareusing.

Power.
+3.3voltstoVcc
ground
Communications.
TxDontheboardtoRxDontheadapter
RxDontheboardtoTxDontheadapter
Ground
Jumpers.
ConnectVcctoCH_PDtoenablethechip
ConnectGPI0toGNDtoenableflashreprogramming

HowdoIinstallNodeMCUonmyESP8266?
PlugtheUSBtoserialadapterintoyourPC.MostadaptersareautomaticallyrecognizedbyWindows7and8.UsersofXPorolderversionsof
WindowsmayneedadriverwhichshouldbesuppliedbythemanufactureroftheUSBadapter.TheadapterwillappearasanewCOMporton
yoursystem.ChecktheDeviceManagerifnecessary.
RunESP8266Flasher.exe

IfyouonlyhaveoneCOMdevice,theportwillappearautomatically.Ifyouhavemorethanone,selectthecorrectonefromthedropdown
menu.
http://benlo.com/esp8266/esp8266QuickStart.html

3/7

11/28/2015

ESP8266QuickStartGuide

TheflasherprogramcomeswithdefaultNodeMCUfirmwareinmemory.Thisisunlikelytobethelatestversion,buttogetstartedquickly,use
thedefaultinternalimage.Later,youcandownloadthelatestfirmware,thenselectthe[Config]tabandchoosethenew.binfile.Selectthe
0x7C000defaultand0x7E000blanksections.Unchecktheboxforthe0x10000IROMsection.
ClickonFlash(E)tostarttheprogrammingprocess.IftheMACaddressesdon'tappearwithinafewseconds,disconnectthepowertotheboard
andreconnectit.Ifitstilldoesn'twork,checkyourconnections.MakesurethatthejumperbetweenGNDandGPIO0istheresothattheboardis
inreflashmode.
Reflashingthechipwilltakeacoupleofminutes.Whenthejobisdone,disconnectpowerfromtheboardandremovethejumperfromGND
toGPIO0toleavereflashmode.
YouarenowreadytoprogramtheESP8266foryourownapplication.

HowdoIcommunicatewiththeESP8266?
TheNodeMCULuafirmwareyouhavejustinstalledcommunicateswiththePCovertheseriallink.YoucanusePuTTY,SimpleTerm,orany
otherterminalprogramthatyouliketowriteLuaprogramsorenterdirectcommandstotheboard.Thedefaultspeedis9600baud,butthatcan
bechangedtoanyotherbaudrateonceyouhaveestablishedcommunications.

LuaLoader
LuaLoaderisaWindowsprogramforuploadingfilestotheESP8266andworkingwiththeLuaserialinterface.Aswellasbeingasimple
terminalprogram,ithasbuiltinLuacommandbuttonsthatmakeiteasytointeractandexperimentwiththeESP8266board.
Download:LuaLoader.zip
LuaLoader.exeisasimpleWindowsapplicationthatrequiresnospecialinstallation.

FromtheSettingsmenu,selectCOMPortSettingsandchoosetheappropriateCOMportforyourUSBtoserialadapter.Don'tchangeany
othersetting.
ClickingbuttonsonLuaLoadersendscommandstotheboard.Poweryourboardandwatchfortheinitialmessage.Afterdisplayingsomefunny
characters(thesearefirmwareresetparameterssentat74880baud),youshouldseetheversioninformationoftheNodeMCUbuild:
NodeMCU0.9.5build20150107poweredbyLua5.1.4
LuaLoaderwillwarnyouifalaterfirmwarebuildisavailable.
Afterbooting,NodeMCUwillattempttorunafilecalledinit.luainflashmemory.Sinceyouhaven'tputitthere,itwillreportanerrorandshow
the>prompt.YouarenowreadytointeractwithLuaontheESP8266.

ClicktheHeapbuttontodisplaytheamountofRAMavailable.LuaLoaderwilltypethecommand=node.heap()and
theESP8266willrespondwith23016orsomeothervalue,followedbythe>promptagain.
http://benlo.com/esp8266/esp8266QuickStart.html

4/7

11/28/2015

ESP8266QuickStartGuide

HowdoIconnecttoanAccessPoint?

EntertheSSIDandpasswordofyourclosestaccesspointintheappropriatetextboxonLuaLoader.
ClickSetAP.LuaLoaderwilltypethecommandstosettheWiFimodeandconnect.Thisinformationissavedinflashmemoryandwillbe
remembereduntilchanged,eveniftheboardispowereddown.
Clickthe

WiFibuttontochecktheconnectionstatus.

ClickGetIPtoconfirmthattheESP8266isconnectedtoyouraccesspoint.

ClicktheSurveybuttontolisttheavailableaccesspointsvisibletotheESP8266.The
SSID,authenticationmode,signalstrength,MACaddressandchannelareshown.
AllofthecommandstypedbyLuaLoadercanbeenteredmanually,orsavedinafiletoberunautomatically.

HowdoIreadaGPIOinput?
TheLuafunctiongpio.read(pin)readsthevalueoftheinputspecifiedbypiniftheGPIOhasbeensetupasaninput.

LuaLoadermakesthiseasytotest.Selectpin3GPIO0fromtheGPIOdropdownmenu,
selectinputandfloatingfromthemodedropdownmenus.ClickSet.Then,clickRead.Thecurrentpinvaluewillbe0or1.Inthiscase,1asthat
pinisheldhighnormally.
NotethatifGPIO0islowonreset,thechipwillenterreflashingmode,soyoumustensurethatanyuseofthatGPIO0foruserinputishigh
whenthedeviceispoweredonorreset.
Toreadthevalueoftheinputpinrepeatedly,inLuaLoader,clickontheclockbesidetheReadbutton.Note,thatifyouareusingtheNodeMCU
developmentboard,thebuttonmarkedFLASHwillchangethevaluefrom1to0whenthebuttonispressedasitisconnectedtoGPIO0and
ground.ThereadratecanbechangedintheSettingsmenu.

HowdoIsenddatatoaserver?
Thedemoscripthttpget.luaconnectstothiswebserverandsendsthetimeittooktoconnect(inmicroseconds)andtheamountofheap(RAM)
availableatthattime.
Downloadthescripttoyourcomputer,thenuploadittoyourESP8266usingtheUploadFilebutton.
testedonNodeMCU0.9.5build20141222...20150108
sendsconnectiontimeandheapsizetohttp://benlo.com/esp8266/test.php
print('httpget.luastarted')
Tstart=tmr.now()
conn=nil
conn=net.createConnection(net.TCP,0)
showtheretrievedwebpage
conn:on("receive",function(conn,payload)
success=true
print(payload)
end)

http://benlo.com/esp8266/esp8266QuickStart.html

5/7

11/28/2015

ESP8266QuickStartGuide

onceconnected,requestpage(sendparameterstoaphpscript)
conn:on("connection",function(conn,payload)
print('\nConnected')
conn:send("GET/esp8266/test.php?"
.."T="..(tmr.now()Tstart)
.."&heap="..node.heap()
.."HTTP/1.1\r\n"
.."Host:benlo.com\r\n"
.."Connection:close\r\n"
.."Accept:*/*\r\n"
.."UserAgent:Mozilla/4.0"
.."(compatible;esp8266Lua;"
.."WindowsNT5.1)\r\n"
.."\r\n")
end)
whendisconnected,letitbeknown
conn:on("disconnection",function(conn,payload)print('\nDisconnected')end)

conn:connect(80,'benlo.com')

ConnecttoyouraccesspointfirstusingtheSetAPbutton.ThisisnotnormallynecessaryifyouhavesetthecorrectAPsincethelasttimeyou
flashednewfirmware.
Usethedofilebuttontorunthefileyouhavejustuploaded.
Thecontentsoftheretrievedpageshouldbedisplayed.

Feelfreetousemyserverforafewtests,butpleasechangetoyourownwebserverorsignupforoneofthepublicinternetofthingsservers,
suchasthingspeak.com.Claudiuchiruhaspostedanexampleofsendingtemperature(usinganinexpensiveBS18B20I2Csensor)to
thingspeak.com.
ThissimplescriptisallittakestomakeusefulgadgetsfromthesimplestESP01board.Theboardcanbeconnectedsothatitreceivespower
whenadeviceison,abuttonispressed,motionisdetected,amagnettripsareedswitch,etc.etc.
Thephpscriptwillreceivethesignalandcanbeprogrammedtosendanemail,sendansms,pushanotificationtoyourphone,orsimplylog
eventsforfuturereference.
OurwellpumpisnowmonitoredbyanESP01runningasimplescriptonceevery30secondswhenthepowerison.Aswellasloggingthe
activityandsendingadailyemailreport,thescriptsendsoutemergencynotificationsifthepumprunsformorethan2hours,orhasn'trunfor
morethan36hours.
AmotiondetectorwitharelayturnsonanotherESP01whichrunsthesameprogrambutcallsadifferentphpscripttoalertmewhenthereis
motioninfrontofthehouse.Myphonereceivesthealertbeforethedoorbellispressed.

HowdoImaketheprogramrunautomatically?
WhentheESP8266starts,itrunstheinit.luafile.Simplycreateafilecalledinit.luawhichrunsthefilewithyourprograminstructions.Itisalso
agoodplacetoinitializeanyvariablesyouareusing,suchastheSSIDoftheaccesspoint.Whiledebugging,itisagoodideatouseatimerto
callyourfileafterafewseconds.Ifyoumakeamistake,causingacrash,youwillhaveafewsecondstostopthetimerwiththetmr.stopbutton
http://benlo.com/esp8266/esp8266QuickStart.html

6/7

11/28/2015

ESP8266QuickStartGuide

beforetheprogramstartstorunagain.Fortheexampleabove,onelinewilldo:
tmr.alarm(0,10000,0,function()dofile('httpget.lua')end)
Armtimernumber0toexecutethefunctiondofile('httpget.lua')in10seconds.

HowcanIlearnmore?
TheHelpmenuofLuaLoaderhasalargenumberoflinkstoESP8266andLuaresourcesforconvenientaccesswhileprogramming.Thereis
alsoamenuitemlinkingfilesonyourcomputeryoumayhavedownloadedforreference.
UsefulLinks:
NodeMCULuaAPIReference
Theesp8266communityforum.Lotsofsamplescripts.
TechnicalOverviewoftheESP8266byNurdspace
Lua.org,homeoftheLualanguage.
NodeMCUgithubLuasourceandlatestbinaries
EspressifSystems,manufactureroftheESP8266

Ifyoufoundthispageuseful,youcanbuymeabeer.Donationstosupportthiswebsiteletmeknowthatmyeffortsareappreciated.Youcan
usePayPal,creditcard,orbitcoin.Noamountistoosmall.

Twitter
@GeoNomad
@VE3SUN
@dxmon
MorePages
AndorraCC
TrekEarth
CottageCam
Artworks
Stereograms
Nomadness
Photography
BenloPark
PrivacyPolicy
2015benlo.com

http://benlo.com/esp8266/esp8266QuickStart.html

7/7

You might also like