ACROBOTIC Industries ACROBOTIC Industries

ESP8266: Programming Using The Arduino IDE


Time to complete: 2–10min; Level of difficulty: Beginner

This guide will show you how to start programming the ESP8266 Serial to Wi-Fi module using a development board carrying an ESP-12E module and a USB to Serial adapter. Simply connect the board to a computer and start programming it using the Arduino IDE!

List of Materials

What is the ESP8266?

We've written a very detailed account of the ESP8266 System On a Chip (SoC), if you want to find out the full story behind this little chip we invite you to read it:

In short, the ESP8266 Serial to Wi-Fi SoC was released in the summer of 2014, and it has become a center point in the development of inexpensive IoT applications.  Given that Wi-Fi chips have been available for around a decade, you may be wondering what makes the ESP8266 special.  Besides being released at the 'right' time, meaning as Internet Of Things (IoT) have entered everyday speak among developers and tech entrepreneurs, there are a few reasons behind its meteoric rise in popularity:

  • Very capable microcontroller (32-bit 80MHz, built-in Wi-Fi, adequate I/O buses and peripherals; full specs below)
  • Extremely low-cost; ~$1 in moderate volumes)
  • Open SDK that works with GCC
  • Demonstrated ability to run Lua (NodeMCU), JavaScript (Espruino), and Python (MicroPython) interpreters!
  • Arduino IDE integration

The ESP8266 is the SoC onboard the ESP-12E Development Board, and on the next few steps we'll learn how to set up our computers to be able to communicate with and program this chip.

Step-by-step Video

We've made a video following the process described in this tutorial, if that's your preferred media for tutorials go right ahead:

Programming the ESP8266 (ESP-12E) from Arduino IDE

The Arduino IDE

We start by downloading the Arduino IDE or Arduino Environment (both short for Integrated Development Environtment), which is a computer program that'll allow us to write code and upload it to an Arduino development board.  At the time of this writing, the latest version of the program is (1.6.8).

The program is available for OS X, Linux, and Windows.  The download links are availble at:  

Once downloaded, installing the Arduino IDE is no different than installing any other program or application on our system.

Double click the zipped file to extract the Arduino app.  You can execute it from it's current location, but it is common practice to move it to your Applications folder.  The quickest way is to drag and drop it using Finder.

Drag and drop Arduino App onto the Applications directory

Connecting the Board

Using the Micro-B USB cable, connect the ESP8266 Development board to a USB port on your computer.  If the port is working properly, you should see a blue LED on the ESP-12E (near the antenna) blink for an instant, and then turn off.

Installing the USB Driver

No matter what firmware option we choose, we'll need to communicate with the ESP-12E Development Board using a computer's USB interface. The USB to Serial UART module included on the 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.  

Listing device files for USB to Serial UART module CP2012 on the NodeMCU development board

Now that we're ready to communicate with our ESP8266 via the CP2102, we can explore a few of the different firmware options available.

Uploading Your First Program To The Board

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.

Arduino IDE preferences for ESP8266

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.

Arduino IDE boards manager selection for ESP8266

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).

Arduino IDE options for ESP8266 

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!

Arduino IDE WiFi scan results with ESP8266

Comments, questions, or concerns? Drop us a line!.