loading

This Instructable will show you the steps needed to get started with the ESP8266 using a fantastic little development board for the ESP-12E module. The board includes everything needed including a USB to Serial adapter, surface-mount LED, and voltage regulator. In addition, it is easily mountable on a breadboard for developing your own IoT project(s)!

Edit: we now have the steps in this tutorial in video form!

The main goal of the Instructable is to cover all the different options you can use in terms of firmware for developing applications that use the ESP8266 to connect to the web. The content, although available, is scattered throughout various sites around the web thus we decided to condense it in one place.

Excited? Let's get started!

Step 1: What Is the ESP8266?

Since the summer of 2014, the ESP8266 has seen a wide adoption as a cost-effective solution for IoT and WiFi-capable devices. The ESP8266 was developed by Shangai-based Espressif Systems, as a Serial (UART) to Wi-Fi SoC (System On a Chip) based around a Tensilica Xtensa LX3 DPU. This tiny IC includes an RF front end, RAM, and (usually) an onboard TCP/IP stack that allows it ready to connect to a nearby Access Point, to act as an Access Point itself, or both.

Family of Breakout Boards (ESP-NN)

Quickly after launch, a variety of breakout boards for the ESP8266 started becoming available. The most popular ones have been the ESP-NN series, which typically integrate the SoC along with Flash RAM, a crystal, and even an onboard antenna. The most salient distinction between different ESP-NN models are the pins that are broken out from the ESP8266 (for a full list see http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family).

As the ESP8266 was developed as a Serial to Wi-Fi adapter, its firmware implemented an intertrepeter for AT commands. Thus initial usage of the IC was limited to using a either a USB to Serial adapter, or a separate microcontroller (e.g., ATmega328) to issue AT commands over the ESP8266's Serial UART interface. For this reason, the ESP-01 board quickly became popular amongst the ESP8266 community becaue of its 2×4, 0.1in-pitch connector that can be easily wired to a USB to Serial adapter. The connector gave access to the pins used for serial communication, namely RX and TX, as well as 4 control pins, GPIO0, GPIO2, CH_PD and RST (reset), along with VCC and GND.

However, other ESP-NN boards offer access to a wider variety of pins, although their packaging is of a custom Surface-Mount Device, with castellated pins as seen in the documentation page linked above. From the different ESP-NN boards, we began to experiment with the ESP-12E. The main reason is that this module was the one chosen by the developers of the NodeMCU project for their hardware DevKit 1.0 (see Firmware Options for details about NodeMCU).

Because the ESP8266 provides a cost-effective solution to the rapidly growing market of internet-connected projects and devices (i.e., the so-called Internet Of Things), it has become one of the most popular development platforms over the past year and a half. In consequence, a dedicated community has formed around the platform (http://esp8266.com), which has been focused on improving its functionality. For starters, different firmware options have been ported to run on the ESP8266, effectively taking it from a simple Serial to Wi-Fi adapter into a fully functional microcontroller with access to its GPIO and hardware-based functions like PWM, I2C, 1-Wire communication, and ADC; all this, of course, in addition to maintaining its Wi-Fi capabilities.

Step 2: List of Materials

For this Instructable we'll be using the following materials:

1 x ESP8266 (12-E) Development Board with onboard USB-to-Serial

1 x USB-A to Micro-B Cable Male/Male (3ft)

Step 3: Firmware Options

A few different firmware options are available for the ESP8266. These allow us to access the module in different ways, as you can see below.

AT Command Processor (Default)

The quickest way to get started with the ESP8266 is to use its original firmware, which allows it to process any AT commands that it receives over its Serial UART interface. The biggest advantage of this option is that we need not be familiar with any specific language or framework to use the module. We can simply send it a series of commands to achieve our goal. The downside to this is that we need either an additional microcontroller involved or a USB to Serial adapter to send the necessary commands.

For the full list, please see the documentation (https://acrobotic.com/downloads/ESP8266_at_commands.pdf).

Whereas the AT commandsare the standard way of communicating with wireless-capable ICs (e.g., Bluetooth, Wi-Fi, GSM), they pose the limitation of needing another module to run the application that specifies these commands accordingly. However, if we could run the application within the ESP8266 itself then we'd have everything self-contained by a single IC. Fortunately, Espressif made a Software Development Kit (SDK) available that allowed users to flash different firmware options.

NodeMCU

NodeMCU is, at the moment, the most popular alternative for firmware running on the ESP8266. Based on the eLua project, it runs a Lua interpreter onboard the ESP8266, which is able to execute commands written in the Lua scripting language. The commands are sent to the ESP8266 via the Serial UART interface.

NodeMCU is a great starting point for Makers as it provides an interactive environment that allows running commands not only for controlling the ESP8266's wireless interface, but also its GPIO and hardware functionality such as i2c and PWM. In addition, we have access to the full scope of the Lua programming language for writing our applications. In the case of the default firmware (AT Commands Interpreter), the application code would have to be developed using a programming language suited to the microcontroller or SoC we use to develop the interface for sending the commands over Serial (e.g., C/C++ for microcontrollers in the Arduino boards).

Finally, not only does the NodeMCU firmware allows us to execute commands interactively, but we can save our applications as a script in the ESP8266's flash memory, and instruct it to run the application code every time it restarts! Even though this is a convenient option, our preferred method of working with the ESP8266 is to write our own firmware using the Arduino framework (details below).

Custom Firmware (using the Arduino IDE)

Whereas the NodeMCU Development Board is shipped with the latest version of the NodeMCU firmware, we can very easily replace it using the Arduino IDE. This allows us to run our own firmware on the ESP8266, which executes every time the module is powered. Even though this method erases the NodeMCU firmware from the ESP8266's flash memory, it is a straight-forward process to go back to using it!

Other

For advanced users, there is the esp-open-sdk toolchain which allows us to progam the ESP8266 directly (more info at the esp8266.com wiki) without having to use the Arduino IDE for uploading the code to it.

This neat little SoC has also received the attention from the Espruino and MicroPython communitites. Both MicroPython and Espruino are fantastic interpreters (Python for the former and JavaScript for the latter) that can run on embedded platforms. However, both of these options are still in very early stages of development for the ESP8266 and not all functionality is availab

Step 4: Installing the USB Drivers

The USB to Serial UART module included on the NodeMCU Development Board is Silicon Labs' CP2012, for which we usually need to install the readily available Virtual COM Port (VCP) drivers.

Once installed, we can verify that the CP2102 is recognized by the computer. After connecting the USB cable to both the USB port on the computer and the board, we can open a terminal window and list the available devices by:

ls /dev/tty.*

The device file created to communicate with the CP2102 has the name tty.SLAB_USBtoUART. Now that we're ready to communicate with our ESP8266 via the CP2102, we can explore a few different firmware options.

Step 5: The AT Commands Interpreter

The developers of the fantastic ESP8266 SoC have made available the necessary tools to update the firmware on the module. In our case, we need to use these tools to be able to use the AT Commands Interpreter. As mentioned above, our NodeMCU Development Board comes loaded with the NodeMCU firmware. Similarly, if you're using this guide with other development boards and modules, you might also need to replace their firmware so this will be good practice.

For loading any firmware to the ESP8266 we need two things: a flashing tool, and an image to flash (bear in mind that in this context, the term 'flashing' means writing data to a flash memory storage device).

Flashing tool

There are a few different options for tools that are able to flash firmware onto the ESP8266. Our typical preference leans towards solutions that work on any Operating System (i.e., cross-platform). In this case we'll use esptool, a Python-based ESP8266 flashing tool developed by Fredrik Ahlberg.

From our terminal, we clone the entire repository by:

git clone https://github.com/themadinventor/esptool

Firmware image

With the flashing tool downloaded, the next step is to download the image we want to flash. Same as before, we have a few different options for which image (containing the AT Commands Interpreter) to use. In our case, we'll use the one made available by Electrodragon (as recommended in their wiki). Navigate to their shared folder ESP8266 (Google Drive) and then download the .bin file:

Firmware → AT_Bin files → 0.952 support SmartLink → v0.9.5.2 AT Firmware.bin

Flashing the firmware to the ESP8266

Before being able to use esptool, we need to install the Python module pySerial on our system. This can be done in a few ways depending on your Operating System. One way is to download the module's source code:

git clone https://github.com/pyserial/pyserial

And install it by running the following command in the Terminal (or PowerShell for Windows users):

sudo python setup.py install

With the module installed, we can now flash the image we downloaded using the esptool program. We'll need to know the location of the file in our system as well as the name of the device file or COM port, which in our case are "~/Downloads/v0.9.5.2\ AT\ Firmware.bin" and "/dev/tty.SLAB_USBtoUART" respectively. Then, we can run the esptool program by:

python esptool.py --port /dev/tty.SLAB_USBtoUART write_flash 0x00000 ~/Downloads/v0.9.5.2\ AT\ Firmware.bin

Once this is done, we can start AT commands to communicate with the ESP8266 .

Usage

From the different ways of sending messages over the computer's USB, we're going to use the Arduino IDE's Serial Monitor for this purpose. We only need to choose the appropriate option from Tools → Serial Port → yourserialport (in our case /dev/cu.SLAB_USBtoUART) and opening up the Serial Monitor window. Because we're not going to upload firmware to the board with the IDE, we need not worry about the selected Board, the default Arduino Uno selection is okay.

In the Serial Monitor window we need to first adjust two settings. We set the line ending drop down menu to "Both NL & CR" and also the baud rate to 115200. Once that's done, we can enter the test AT command:

AT

which simply returns an OK message. Then, for instance, we can try to scan for nearby networks by entering:

AT+CWLAP

See the entire list of available commands on the "Firmware Options" step of this tutorial.

Step 6: NodeMCU Firmware and Lua

Firmware image

Similar to what we did before, we want to download an image for the NodeMCU firmware, so that we can use the esptool program to flash it. The latest version of NodeMCU can be downloaded from the project's Github repository.

Flashing the firmware to the ESP8266

Once downloaded, we can use esptool as we did before, remembering to change the name of the image file and device:

python esptool.py --port /dev/tty.SLAB_USBtoUART write_flash 0x00000 ~/Downloads/nodemcu_float_0.9.6-dev_20150704.bin

Usage

Because the NodeMCU firmware is a Lua interpreter we're need to make use of the fantastic Java-based tool written by Victor Brutskiy, the ESPlorer. For a comprehensive getting started guide covering the ESPlorer tool, refer to Rui Santos' documentation.

After making sure that the latest Java Runtime Environment (JRE)and the Java Development Kit (JDK) are installed (and their versions match), we can simply double-click the ESPlorer.jar file inside the .zip archive we downloaded. The first thing we want to do in ESPlorer is configure the baud rate to 9600 and select the correct device from the drop-down menu (in our case /dev/u.SLAB_USBtoUART). We can then click on Open to start communicating with the ESP8266.

After we've established communication with the device we can start running code written using Lua. In the ESPlorer's editor we can write the simple script:

-- print ap list
function listap(t)      
    for k,v in pairs(t) do        
        print(k.." : "..v)      
    end
end
wifi.sta.getap(listap)

Once we're done, we can click on the "Send to ESP" buttons in order to send the code to the NodeMCU Lua Interpreter running on the ESP8266. After the code runs, the ESP8266 sends back a response that is displayed in the output window of ESPlorer containing a list of the nearby Wi-Fi networks.

In a follow-up tutorial featuring the ESP8266, we'll show you how to make the code run automatically, every time the ESP8266 starts.

Step 7: Custom Firmware With the Arduino IDE

For those of us who want to use the ESP8266 as a regular microcontroller such as the ATmega328 in the Arduino UNO, then it's possible to write custom firmware and load it on the chip. As is typical in programming microcontrollers, the custom firmware will replace anything previously stored in the chip's flash memory.

Although we can use the manufacturer's SDK to develop our custom firmware, it is much easier to use the good ol' Arduino IDE. If you don't have it installed, please look at our detailed tutorial on how to get it on your system.

In the Arduino IDE open the Preferences window and enter the URL below into the Additional Boards Manager URLs field, and select OK.

http://arduino.esp8266.com/stable/package_esp8266c...

Select the menu option Tools → Board → Boards Manager... and scroll down and to locate the option esp8266 by ESP8266 Community which should be the last item on the list, and click Install.

After restarting the Arduino IDE we can now select the board we're using from the menu option Tools → Board → NodeMCU 1.0 (ESP-12E Module). Then, we specify the correct CPU Frequency (Tools → CPU Frequency: "" → 80MHz) and Upload Speed (Tools → Upload Speed: "" → 115200). Finally, the last step is to select the correct option for the Port (Tools → Port → /dev/cu.SLAB_USBtoUART).

At this point we can write our own firmware and upload it. To get started we can try one of the examples File → Examples → ESP8266WiFi → WiFiScan. After uploading it, we can open the Serial Monitor window and observe the results. Note that we need to match the baud rate, so check that 115200 is selected from the drop down menu

<p>Hey ! I'm new and I would like to know if it's possible to turn my nodemcu esp8266-12e as an acces point to internet ? Or juste to grap internet with it. My computer didn't have a wifi chip, i need an ethernet cable and I want to use the wifi chip of my nodemcu to get acces to internet with the wifi of my router on my computer. Possible ?</p>
<p>HELLO, I CANT GET MY WIFI TO WORK, PLEASE HELP?:)</p><p>&eth;&eth;AT</p><p>OK</p><p>AT+CWMODE=1</p><p>OK</p><p>AT+CWMODE?</p><p>+CWMODE:1</p><p>OK</p><p>AT+CIFSR</p><p>+CIFSR:STAIP,&quot;0.0.0.0&quot;</p><p>+CIFSR:STAMAC,&quot;60:01:94:0f:7f:32&quot;</p><p>OK</p><p>AT+CWJAP=&quot;SINGTEL(5G)-7787&quot; , &quot;0015103879&quot;</p><p>ERROR</p>
<p>I recommend using the Arduino IDE with the Arduino ESP8266 Core installed. If you are new to C programming, then check out TUNIOT, a version of BlocklyDuino Enhanced with WiFi code blocks developed for the NodeMC board. You can plug code blocks together like in Scratch or Blockly and the resulting code is Arduino C. They have a series of tutorial videos on using TUNIOT with the Arduino IDE and NodeMCU board on YouTube. I'll give the links below. There Tutorial #10 will show you how to get a HTTP WiFi Server up and going. The web page is a &quot;one liner&quot;, but if you know how to code HTML, you can create a pretty nice web page. You can create a webpage with a banner, a couple pages of text, a bunch of hyper-links and a number of photos, I use the old HTML &lt;table&gt; tags to format the layout, but if you know CSS, you can use &lt;div&gt; tags and in-line CSS to do your layout. Have yet to play extensively with CSS, but the basics seem to work fine. The images I display are hosted on another webserver on the Internet as the NodeMCU has limited Flash memory for storage. Just use the complete URL and it should pull up the image w/o problem. Maybe I should do an instructable.</p>
<p>Ooops... Forgot the links I'd promised:</p><p>TUNIOT IDE (Hosted on a Server out on the Internet): </p><p>http://easycoding.tn/tuniot/demos/code/</p><p>TUNIOT Tutorial Videos on YouTube:</p><p><a href="https://www.youtube.com/playlist?list=PLfPtpZzK2Z_Qy2ZbbzvWa58cKKOisMUZ1" rel="nofollow">https://www.youtube.com/playlist?list=PLfPtpZzK2Z_...</a></p><p>For Arduino Uno/Mega/Nano/Etc. users, they also have a version of BlocklyDuino-Enhanced for non-WiFi applications at this URL:</p><p><a href="http://easycoding.tn/bde/demos/code/" rel="nofollow">http://easycoding.tn/bde/demos/code/</a></p><p>A Google search on &quot;BlocklyDuino&quot; will also produce a list of other &quot;flavors&quot; of BlocklyDuino with different set of code blocks, so specialized for specify hardware, like the Grove modules, etc.</p><p>The BlocklyDuino and TUNIOT languages are great for middle and high school students just learning Arduino C, and for forgetful old coots like me whose memory often fails to recall all the details for coding Arduino C functions, etc.</p>
<p>why wont my 8266 connnect to my windows 10 laptop oon tutorials by</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/-a2-p0GKIdw" width="500"></iframe></p><p>it shows he plugs in and his laptop/pc connects but mine dosnt ive tried looking for driver links.</p><p>can someone post the video above but instead of using a mac use a windows platform laptop/pc </p><p>im a motor vehicle mechanic not a programmer but have an invention i need to make hoprfully using the node 8266 as a on and off switch with a distance of 25meters minimum can it be done or will i need additional items such as a transmitter board say like whats on a drone ,what im inventing i need to turn on and off like a light switch,i got my idea whilst flying my drone which i can control the motors to turn on or off...</p><p>if anyone has any idea if this will work and if i need more bits but most of all how to get it to connect to my laptop,that be a great start cheers all</p>
<p>Found this tutorial instead of the above video making it sound hard i followed this </p><p><a href="http://randomnerdtutorials.com/flashing-nodemcu-firmware-on-the-esp8266-using-windows/#comment-293823" rel="nofollow">http://randomnerdtutorials.com/flashing-nodemcu-fi...</a></p><p>and well it was easy as 123 </p>
<p>@eduardov1:</p><p>The LoLin board (which has the same form factor as those Amica v0.9 NodeMCUs... which means it's not very breadboard friendly (I use a pair of mini breadboards and space the MCU between the two)) but I digress) has the CH340G USB-to-UART Bridge chip which requires its own driver with WinXP, Win7, and early versions of Win8 (as well as Mac OS-X Yosemite and El Capitan , and perhaps some early distributions of Linux.) Here is a link:</p><p><a href="http://kig.re/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html" rel="nofollow">http://kig.re/2014/12/31/how-to-use-arduino-nano-m...</a></p><p> to a website that discusses this problem fow the inexpensive Chinese versions of the Arduino Nano which uses the same CH340G chip and the drivers you download from there should work for the LoLin NodeMCU V3. </p><p>Here is an image of how I connect up a LoLin NodeMCU V3 using two mini breadboards. Seems there is like a 1.5cm gap between the two mini breadboards.</p><p>-WRM</p>
<p>Also, there seems to be three major providers of NodeMCU boards: Amica, DoIt, and LoLin. Each has boards which use the CH340G and both Amica and DoIt has switched to the Silicon Labs CP2101 (not sure why, the CH340G always works well for me. I have them on my several Arduino Nanos, WeMos D1 WiFi boards and LoLin NodeMCU boards. </p><p>[Note: There appear to be a few other USB-to-UART bridge chip manufacturers, but on Node MCUs I have only seen the CP2102s and the CH340Gs. However, if you work with those AI-Thinker (or similar) ESP-xx WiFi modules, then you may decide to buy a general purpose TTL UART to USB adapter and I have seen versions of this kind of module board which use two other vendor's chips as well. These other two USB-to-UART bridge chips are the FTDI F232R and the Taiwanese Prolific Technologies PL2303, so I suppose you may need to download drivers for either of these should you happen to buy one for use with say an ESP-01 or ESP-12E module.]</p>
<p>This was amaizing! </p><p>I have a problem, my 8266 (Lolin it says nodemcu v.3...) is not detected in windows anymore!! but windows detects arduino (seem that the problem is not the usb port nor the driver) Any ideas?? I was using an OLED and I pressed reset and stopped working, the blue light work, though. </p><p> Thanks so much!</p>
<p>I have the same problem. Have you solved it per chance?</p>
Thanks for checking out our tutorial! <br><br>Usually unplugging the board and re-plugging it back into the USB port works. It gives the driver a chance to re-establish the connection.<br><br>Navigate to your Device Manager, and expand the Ports (COM &amp; LPT) category. As you plug/unplug the device from the computer, an entry should appear in there.<br><br>Also, try a different USB port on your computer as a sanity check. Let us know if neither of these solutions work for you!
<p>Hmmm it is a fantastic idea to put all of this in one place - thank you. Shame your links and descriptions couldn't be in plain English ... a sure gap in the market for someone.</p><p>However, my terminal prog in windows xp says it is connected at port 21 but I get no response from any entered AT commands.</p><p>Can the ESP8266 MCU USB module have many 'sketches' installed at the same time? I can not get a directory of the files nor a heap even though lualoader tells me it is connected and I've flashed / installed / loaded several files as the various webs seem to suggest. Perhaps it is broken.</p><p>I get a pile of junk characters when it connects and then nothing Certainly nothing on my wireless lan to say it is even existing. Right now I don't see the point of the thing and am pining for my reliable and intuitive Arduinos.</p><p>I shall cook the family Sunday roast and get back to it this evening ... </p>
<p>is iit now working?</p><p>i too have same problem what to do? please respond</p>
<p>Just wanted to say thank you for your hard work putting this together. </p><p>Even with this guide it was a mission, so for you to put this together must have taken quite a few days of work. But at the end of the day it all worked. </p><p>So it is possible for a total beginner like myself to make it happen. Learnt about github, python, using terminal in mac, </p><p>Cheers,</p><p>denn...</p>
<p>maybe its your ssid and password of your internet at home.. becous your on the router but no connection/</p>
<p>Hello all </p><p>I have a problem about nodemcu esp 8266</p><p>I wrote a script for nodemcu by lua loader but when I reset cheap the script has been deleted is there any way to save program whiteout any external memory on it's memory?</p><p>thanks</p>
<p>HI</p><p>Plugged in my first esp8250 board and all worked fine Wi-Fi and all. Tried the blink app an now AT commands do not reply.</p><p>On reset I get </p><p><em>ets Jan 8 2013,rst cause:2, boot mode:(3,7)</em></p><p><em>load 0x4010f000, len 1264, room 16 </em></p><p><em>tail 0</em></p><p><em>chksum 0x42</em></p><p><em>csum 0x42</em></p><p><em>~ld</em></p><p><strong>Any recommendations - I have tried AT-RESTORE but no luck.</strong></p><p>If I get this thing working I will join the club.</p><p>Thanks</p><p>Bob</p>
<p>Hi,</p><p> I have started working on ESP8266(8-Pin). I have flashed it using firmware version nodemcu_integer_0.9.6-dev_20150704.bin.Just after flashing it shows a Wi-Fi signal in my cell phone and computer. but when i start with AT commands wifi signal gets off.</p><p>I am using AT commands to get the IP of that particular ESP module so that i can connect with android apps. Its not responding the AT commands. its shows its getting the AT commands but not giving response of that command.</p><p>AT</p><p>&gt;</p><p>AT+RST</p><p>&gt;&gt;</p><p>AT+CIFSR</p><div>&gt;&gt;<p>I m getting response Like this.</p><p>I have also tried with lualoader.</p><div>Baud rate changed to 115200<p>= node.heap()</p><p>35184</p><p>&gt; = wifi.sta.getip()</p><p>nil</p><p>&gt; = wifi.sta.getip()</p><p>nil</p><p>&gt;&gt; = wifi.sta.status()</p><p>3 AP NOT FOUND</p><p>&gt; </p><p>I have also tried to fix the IP by using this code by making init.lua</p><div>wifi.setmode(wifi.STATIONAP)<p>wifi.setmode(wifi.STATION)</p><p>wifi.sta.config(&quot;SSID&quot;,&quot;PASSWORD&quot;)</p><p>wifi.sta.setip({ip=&quot;192.168.0.136&quot;,netmask=&quot;255.255.255.0&quot;,gateway=&quot;198.168.0.1&quot;})</p><p>After that IP is fixed but the problem is, i m not getting the WiFi signal in my Computer and Cellphones. so i m getting problem to communicate with android apps. So, Please tell me how to solve these issues. If you are suggesting any firmware please attach it. Because i m getting so many firmware version on Github.</p><p>Send me a video or no. of steps how to solve this issues. </p><p>chandankr502@gmail.com</p></div></div></div>
<p>very interesting and condensed !</p><p>Thanks a lot.</p>
Thanks for checking it out. Glad you liked it :)
Wow! Fantastic primer! Thank you
:) Thanks! We're very glad you liked it.

About This Instructable

170,426views

458favorites

Bio: Designing fun, unique, and Open-Source electronic kits for education, DIY, hobby, art, science, and more. For the tinkerer in all of us!
More by acrobotic:Get Started with ESP8266 Using AT Commands, NodeMCU, or Arduino (ESP-12E) Raspberry Pi  Bluetooth LE Controller for WS2812B (NeoPixels) Control Bluetooth LE Devices From A Raspberry Pi 
Add instructable to: