Installing and Building an Arduino Sketch for the $5 ESP8266 Microcontroller

Arduino Internet of Things Maker News
Installing and Building an Arduino Sketch for the  ESP8266 Microcontroller
Custom build of the Arduino IDE with support for the ESP8266 chip and the esptool programmer.
Custom build of the Arduino IDE with support for the ESP8266 chip and the esptool programmer.

Part 2 of a 3-post series on the new ESP8266 microcontroller

From our look at the $5 ESP8266 WiFi microcontroller and the new Arduino-compatible development environment that’s just been released, let’s get to work testing it out.

Installation of the custom build of the Arduino IDE really couldn’t be simpler. I’m on a Mac, and at that point it comes down to downloading the pre-built binary release from GitHub. The custom binary will live quite happily alongside your existing stock Arduino development environment — in fact, as well as the ESP8266 build, I think I’ve got six or seven other versions of the environment installed at the moment, with version numbers ranging from 1.0.x up to to latest 1.6.x build.

However, despite it being manageable, having a whole separate environment installed isn’t actually necessary. One of the things that the new 1.6.x release of the Arduino environment introduced was much more simplified support for adding and managing new boards.

Blinking an LED using an Arduino sketch and a MOD-WIFI-ESP8266-DEV board. (Credit: Sandeep Mistry)
Blinking an LED using an Arduino sketch and a MOD-WIFI-ESP8266-DEV board. (Credit: Sandeep Mistry)

Which is exactly what Sandeep Mistry has now done with the ESP8266. Installation is almost as simple as before — download it and move the esp8266com folder included in the release inside the hardware folder of your Arduino sketchbook directory.

Wiring up the ESP8266 Module

The pin out for the header block of the ESP-01 module
The pin out for the header block of the ESP-01 module

As I mentioned before, probably the most common breakout board you’ll come across for the ESP8266 is the ESP-01. Now unfortunately while the ESP-01 module has a standard spaced header block on one end, the pin out is rather inconvenient when dealing with breadboards. Because of the way the pins are laid out, you can’t just plug the module directly into a breadboard, you’re going to have to break out some jumper cables.

You’ll need to connect the VCC pin to a +3.3V supply, and the GND pin to ground. The board’s RX should be connected to the TX from your computer, and the board TX should be connected to the RX from your computer.

Additionally, to enable the board, you’ll need to pull the CH_PD pin high to +3.3V, and to allow you to upload your sketches you need to put the ESP8266 into bootloader mode by pulling the GPIO_0 pin low and toggling power to the board.

The two easiest methods to attach the board to your computer, so you can load your Arduino sketch onto the ESP8266, are either to use an FTDI adaptor board — like the FTDI Friend — or a standard FTDI cable.

The ESP-01 wired up to an FTDI adaptor. The CH_PD pin is pulled up to +3.3V to enable the board, the GPIO_0 pin is pulled down to GND to enable firmware upload.

Just remember that, if you use a cable, you’ll also need to use a 3.3V regulator, or go ahead and build a voltage divider out of resistors, as the FTDI cable runs at 5V and the ESP8266 runs at just 3.3V.

The ESP-01 wired up ready to be connected to a standard FTDI cable. The CH_PD pin is again pulled up to +3.3V to enable the board, whilst the GPIO_0 pin is pulled down to GND enabling firmware upload. Note the 3.3V regulator between the +5V input and the ESP-01 board.

After the sketch is uploaded you will need to remove the jumper between GPIO_0 and GND for things to work correctly.

Uploading the Sketch

The use case for the ESP8266 is controlling things via the network, it’s a classic Internet of Things platform. Let’s start off by doing some Internet of Things like things by flashing an LED on and off using the web. After all, if you can turn an LED on and off, you’re halfway to anywhere.

An LED attached to the free GPIO_2 pin of the ESP-01 board.
An LED attached to the free GPIO_2 pin of the ESP-01 board.

Go ahead and wire up your LED in the normal way to the spare GPIO pin, that’d be GPIO_2, and then open the Arduino IDE. Select “Generic ESP8266 Board” from the Tools → Boards menu, and the serial port your board is connected to from the Tools → Ports menu. Finally select “esptool” from the Tools → Programmer menu.

Now go to the File → Examples → ESP8266WiFi menu and load the “WiFiWebServer” sketch into an editor window. Replace the placeholders values in the script for “ssid” and “password” with the SSID and password for your WiFi network. Then hit the upload button.

If all goes well you you should see that it is “Uploading…” and then, after a while, that it is “Done uploading.” If you encounter an error then you should double check and ensure that the CH_PD pin is pulled high, and the GPIO_0 pin is pulled low. Then toggle the power on the board again to make sure it’s in bootloader mode. You should probably also check that RX is wired to TX, and TX to RX.

Now go ahead and open the Serial Monitor, remove the jumper between the GPIO_0 pin and GND, you toggle the power to the board again. If you do not toggle the power to the board at this stage, you sketch won’t be loaded.

However if all is still going well you should see something like this,

Connecting to Wireless Network
.......
WiFi connected
Server started
192.168.1.224

which tells you that the board has connected to the network, and rather crucially, what the board’s IP address ended up as when it negotiated its connection to the DHCP server.

The ESP-01 board running the “WiFiWebServer” example sketch

Now you can just go to your browser and use the endpoint http://gpio/1 to pull GPIO_2 high, and turn the LED on, or http://gpio/0 to pull GPIO_2 low, and turn the LED off. If you’re still connected to the Serial Console you should see something like this scroll by if you attempt to turn the LED on,

new client
GET /gpio/1 HTTP/1.1
Client disconnected
new client
GET /favicon.ico HTTP/1.1
invalid request

Here you can safely ignore the invalid request error message — that’s just your browser asking for the icon that accompanies the web pages its retrieving, it doesn’t necessarily expect a response — however at this point the LED connected to GPIO_2 should be on. Go ahead and try turning it off again.

If you succeed? Well, done. You’ve just replicated 90% of the functionality of a Philips Hue light bulb and built your first Internet of Things thing.

Now if you look closely at the video you might have noticed something odd about the ESP-01 board I’m using, it’s not connected via an FTDI adaptor, or a standard FTDI cable. Instead, I’m using a breadboard adaptor.

Why should I use the ESP8266?

While the ESP8266 can’t do everything you could do with an Arduino — for instance it only has one PWM pin that isn’t even exposed by the ESP-01 breakout board we’ve used here, you’d have to go looking for something like the Olimex board that Sandeep was using to get access to it — but for $5 it’s a bargain.

For $5 it doesn’t have to do the same amount as you can do with an Arduino, because at $5 you can afford to buy 5 or 6 of them for the price of a single Arduino board.

“This is inexpensive enough to be very much in the territory of ‘thousands of sensors-launched-out-of-a-cannon’-cheap.” — Brian Jepson

The ESP8266 was already well on its way to becoming — almost by stealth — one of the leading platforms for the Internet of Things. It’s super cheap, and super easy to work with, and it’s actually fairly easy — as such things go — to get your hands on, which makes a refreshing change.

However the arrival of Arduino compatibility is step change, suddenly the growing but still small community has opened their platform up to a much larger community. Suddenly there is a huge pool of people that  know how to work with the board, and I think we’re going to see an explosion of projects and products that otherwise wouldn’t get made. Because suddenly we have our hands on a WiFi board, that we all know how to use, that’s almost cheap enough to throw away.

Get out your soldering iron and buy some boards, I’d love to see what you build with it. Especially if it involves cannons.

This is the second of three posts on the ESP8266 microcontroller. Part 1 of the series introduces the board, while the third part talks about creating a breadboard adaptor for the ESP-01 breakout board.

106 thoughts on “Installing and Building an Arduino Sketch for the $5 ESP8266 Microcontroller

  1. Pnáwål Husnoo says:

    Hi Al, nice to see you writing these :-)

    Just before I do something stupid – this is the same connector, right?

    http://uk.rs-online.com/web/p/products/7485316

    1. Alasdair Allan says:

      Yup, that looks to be a standard FTDI connector. However looking at the specification, http://arduino.cc/en/Main/USBSerial, it looks like it operates at +5V so you’ll need a 3.3V voltage regulator.

      1. Gregg Levine says:

        Correct. Also, both FTDI and Sparkfun and Adafruit, make up gadgets who have 3v3 outputs as opposed to 5v only. I believe the majority of these fellows are also available via the Shed,

  2. Clyde Shaffer says:

    Wow. Do they sell these by the bucket? Can I order a quantity that would show up in a literal bucket?

    1. JasonKaler says:

      Yip. But then you can’t brag you got it for $5, cos it will only cost $2.50

    2. Alasdair Allan says:

      You can get them in volume on AliExpress. So for instance here’s a 100pcs lot of the ESP-01 at $2.50 a piece, http://www.aliexpress.com/item/ESP-01-WIFI-Wireless-Transceiver-Module-Send-Receive-LWIP-AP-STA-ESP8266/32259693650.html. So, umm. Probably?

  3. Syed says:

    Seems like I’m missing something…Followed the lDE instruction and got everything showing up in the IDE i.e. ESP chip and examples. However as soon as I hit compile it spits out an error, no error code or line whatsoever, just error compiling .
    Any thoughts ?

    1. Alexander Templeton says:

      warning: espcomm_sync_failed
      error: espcomm_open failed

      1. Syed says:

        Nope no msg. I figured it could be the board settings or a missing header file. If I try compiling an empty sketch with uno selected it compiles fine, but when I select ESP board it simply gives compiling error…strange!

        1. Dêe Vázquez says:

          same thing happens with me! does anyone got a solution for this?

      2. James Heires says:

        Alexander,
        When I follow this tutorial (using a FTDI adapter board and 8266 esp-01 module), I get the “warning” message you cite here.
        Tried various combinations of CH_PD toggle, power toggle, etc between attempts to load the sketch. Tried switching TX/RX lines, to the FTDI, but to no avail (slightly different error message, but no upload success yet).

        1. Alexander Templeton says:

          I haven’t worked out a solution, unfortunately. I’m going to try using a different ESP8266 board, and using an Arduino Mega to program the ‘8266. Also, make sure you’re able to source enough current (the ESP can pull ~300mA.) Please post if you solve it first!

          1. James Heires says:

            Alexander,
            I have a 300mA DC wall wart powering a 7805 voltage regulator, which in turn is powering a 5v-to-3.3v step-down converter, so I assume this is enough power to at least get the 8266 to accept software. I assume all the warnings about enough current to the 8266 is important when transmitting/receiving wifi.

          2. Robin Mglsk says:

            On osx uploading get stuck at:
            espcomm_sync failederror: espcomm_open failed.

            On windows xp running in virtualbox, it writes the program perfectly

          3. Alasdair Allan says:

            Usually happens because it can’t talk to the board at all. Check the wiring on your FTDI cable and make sure you have TXRX and RXTX.

          4. Alasdair Allan says:

            The ESP8266 boards usually run around 85mA or so with WiFi up and running. So that should be fine… that said, a 300mA wall wart is awfully puny. I normally use a 2A one for more-or-less any situation just so I don’t have to worry about that sort of thing.

          5. James Heires says:

            Alasdair, Thanks for the reply. My 1.5A, 12VDC wall wart should be here any day now, so I’ll see if it resolves my issue, and post my observations.

        2. wireddude says:

          I’m getting the following errors when I try to upload, and have made sure that during upload GPIO0 is grounded and VCC goes to CHPD. here’s a warning I get after an upload:

          Sketch uses 203,348 bytes (38%) of program storage space. Maximum is 524,288 bytes.

          Uploading 31808 bytes from /var/folders/9n/dc6sq1r53dj6cqfffhr54wn40000gn/T/build6306005122888019845.tmp/WiFiWebServer.cpp_00000.bin to flash at 0x00000000

          warning: espcomm cmd: didn’t receive command response

          warning: espcomm_send_command(FLASH_DOWNLOAD_BEGIN) failed

          when I try to upload a blank sketch, I get

          espcomm_sync failed
          error: espcomm_open failed

          whenever I try to upload, it seems also to permanently be stuck on “uploading. . .”

          hope someone figures out a solution.

      3. Alasdair Allan says:

        That one is generally happens because the FTDI cable is wired incorrectly. Sure you’ve got TX RX and RX TX ..?

    2. ChayD says:

      I had that issue and this: https://github.com/esp8266/Arduino/issues/54
      fixed it.

  4. Pavel says:

    Thanks for such a great series of articles on ESP8266. It’s finally a truly comprehensive guide. We are currently developing a mobile solution that will support this amazing chip using the same Arduino library. If you would like to try it out – give us a shout at http://blynk.cc

  5. Chan Hao Jie says:

    The esptool does not show up in my Programmers list. But the Board shows up though.

    1. George White says:

      If you’re using the 0.0.2 release of Sandeep Mistry’s plugin port of ESP8266-Arduino support, you won’t see esptool show up in the programmers list. He updated the board definitions to automatically select the correct programmer and removed the ability to select it manually.

      1. Chan Hao Jie says:

        I see. But then the sketch would not compile, I thought it was the Programmer. I’ll post a screenshot later

      2. Chan Hao Jie says:

        The Arduino IDE spits out the following error:
        Arduino: 1.6.2 (Windows 7), Board: “Generic ESP8266 board”

        Using library ESP8266WiFi in folder: D:My DocumentArduinohardwareesp8266comesp8266librariesESP8266WiFi

        Using library ESP8266WebServer in folder: D:My DocumentArduinohardwareesp8266comesp8266librariesESP8266WebServer

        D:My DocumentArduinohardwareesp8266com/esp8266/tools/windows/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -D__ets__ -DICACHE_FLASH -ID:My DocumentArduinohardwareesp8266com/esp8266/sdk//include -c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD -DF_CPU=80000000L -DARDUINO=10602 -DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266 -ID:My DocumentArduinohardwareesp8266comesp8266coresesp8266 -ID:My DocumentArduinohardwareesp8266comesp8266variantsesp01 -ID:My DocumentArduinohardwareesp8266comesp8266librariesESP8266WiFisrc -ID:My DocumentArduinohardwareesp8266comesp8266librariesESP8266WebServersrc C:UsersChanAppDataLocalTempbuild4990457321823963924.tmpHelloServer.cpp -o C:UsersChanAppDataLocalTempbuild4990457321823963924.tmpHelloServer.cpp.o

        Error compiling.

  6. Anthony Paul Frost says:

    “Now go ahead and open the Serial Monitor, remove the jumper between the
    GPIO_0 pin and GND, you toggle the power to the board again. If you do
    not toggle the power to the board at this stage, you sketch won’t be
    loaded.”

    Before coming across this page I was working on passing Wifi data to an arduino via serial connection. I had put in a permanent jumper from VCC to CH_PD and was having a lot of issues. When you toggle power to the ‘board’, you want to toggle power only to CH_PD (not VCC), not the entire board.

    1. Don Pancoe says:

      This tip proved helpful to me. I was toggling Vcc and wondering why the program was lost from memory after restarting. Toggling power to CH_PD only made the program permanent in flash, after which it remained in memory even if Vcc was disconnected and reconnected.

  7. reini says:

    Good guide. Only there is something on the internet already 1000 times. Would be more interesting if it could be used, for example, 5 time off gipos. Still no Dashat managed. I currently testing some more to get shut GPIOs with the MCP 23008 expander. Maybe you can even try something and imagine.

  8. Marius says:

    sadly I cant seem to find the webserver example anywhere in the downloaded file.
    The Linux version wont run but when i check through the downloaded file the example just isnt there. The windows file doesnt have it either.
    I am sure it is me, but what am I doing wrong? I looked in the library folders and in the examples folders

    1. Andy III says:

      I’m having the same issue…all of my sketches won’t compile. Not sure what’s happening.

      I can talk to the ESP, but I can’t upload sketches using the IDE to it.

      1. Marius says:

        I think you forgot to add text :-)

        1. Andy III says:

          Sorry…I solved my own problem then I couldn’t figure out how to kill my comment.
          These things are NEAT!! (Hows that? 8-) )

          1. Marius says:

            great! I am also quite happy with the 8266, just too bad I keep getting errors on the webserver sketch

    2. Brendan Matkin says:

      There was an issue with the Sandeep version for a bit that occurred if you have GitHub for Windows on windows 8.1 64 bit and Arduino version 1.6.3 (a missing .dll). Maybe this is related to the problem you were having. Either way, try version 0.0.4: https://github.com/sandeepmistry/esp8266-Arduino/tree/0.0.4

      1. Marius says:

        Thanks but I tried version 4 and version 5, both give the same problem.
        Any other sugegstions? :-)

        1. Brendan Matkin says:

          Looks like some other people were having Linux problems, especially 32 bit Linux. Check out the issues page of the repository and see if it’s the same issue (and how close it is to being fixed).

          1. Marius says:

            thanks, but i havent seen anything close yet

          2. Marius says:

            There now is a32bit Linux built that compiles errorfree

          3. Slartifartfast says:

            what version please ? I have the same problem using esp8266-Arduino-0.0.5

          4. Marius says:

            latest version that can be downloaded. here i think: https://github.com/esp8266/Arduino
            I got it to work without problems on Linux32 bits

          5. Slartifartfast says:

            Yes I can confirm that the version that Marius links to works for me; Note that it is the main repo, NOT the Mistry fork.

            I loaded the latest Arduino ide (1.6.5) and just followed the “installing with Boards Manager” instructions to add the extension.

            the Mistry fork that I tried earlier gave me that “unterminated quoted string” error that Terry referrred to above, on my linux machine (32 bit Debian Sid kernel 3.9-1-486);

          6. Marius says:

            that is I think how I did it too, albeit i used 1.6.4

          7. Marius says:

            and strangely just now my problem came back

    3. terry says:

      Has anyone found a solution to this issue. I have the same result on Xubuntu 14.04 32b using the sandeepmistry/esp8266-Arduino version 0.0.4 today 29 April 2015.

      Every sketch whether the webserver sample or a blank sketch returns the error “Syntax error: Unterminated quoted string”:

      ~/arduino-1.6.3/hardware/esp8266com/esp8266/tools/linux/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++:
      1: ~/arduino-1.6.3/hardware/esp8266com/esp8266/tools/linux/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: Syntax error: Unterminated quoted string

      ~/arduino-1.6.3/hardware/esp8266com/esp8266/tools/linux/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ returned 2
      Error compiling.

  9. Maaike says:

    Thanks for the article! Very helpful. However. I managed to upload the sketch – or so it seemed, but when I open the serial monitor, nothing ever happens. I removed the jumper, toggled power etc but… nothing. I tried on both a Mac and a PC and the red status light is on, but I can’t get the board to do anything. I wonder what’s wrong?

    1. Brendan Matkin says:

      Did the blue light on the ESP flash while uploading? That is the esp TX light (I think). If it didn’t flicker then nothing uploaded.

      1. Maaike says:

        I don’t remember… and now I only get errors such as “espcomm_sync failed / error: espcomm_open failed”. Is it possible sometimes uploading goes wrong somehow and bricks the ESP unit? Because I eventually got a new one and this one does respond to serial commands. I’m a bit hesitant to try again now.

        1. Brendan Matkin says:

          Maybe? I don’t know enough about it to say for sure. But that is also exactly what happens when the board isn’t in upload mode. To get into upload, pull gpio 0 low (connect it to ground and leave it connected), then turn the board off and on again, then hit upload. You have to do that every time you want to upload something new.

          Make sure you are not using 3.3v from the FTDI board – it cannot supply enough current. You might also try unhooking your LED if it’s still not working – you might have something connected wrong that is causing issues. Once you’ve uploaded a sketch, I don’t think it will respond to AT commands (correct me if I’m wrong anyone), only whatever you’ve programmed it to listen to in your Arduino sketch (if anything).

          There is ALSO a newer version of Sandeep’s fork: 0.0.4. Make sure you are using that and Arduino 1.6.3.

          1. Maaike says:

            Thanks, but I tried all that and still I keep getting these errors. It seems many people get them and there doesn’t seem to be a solution available. Too bad, really.

        2. Pranav Sharma says:

          hey hi, i am having the same problem as u have or had ?
          so i was wondering if you found the solution then can u help me ?
          i am using the latest version of Arduino IDE and Generic ESP8266

          And also i get a message on Serial Monitor “AT+RST”
          help please !!!

          1. Maaike says:

            Please see my message above. In my case it was due to faulty hardware!

        3. Brendan Matkin says:

          This is a bit late and you may have solved it – but if you mean responds to AT commands then sort of yes. The way I understand it is that when you upload arduino code, it overwrites the AT firmware and runs the arduino code as it’s firmware. SO, try installing arduino 1.6.5, follow the ESP8266 arduino github readme instructions for installing from the Boards Manager, and try again! If it’s not responding then you need to be sure you’ve put the esp in bootloader mode (see this page and follow the instructions carefully: https://github.com/esp8266/Arduino/blob/esp8266/hardware/esp8266com/esp8266/doc/boards.md).

          1. Maaike says:

            Thanks! I actually solved it by getting new ESP’s and replacing my FTDI chip (I’ve think I’ve now got a CP2102). Works like charm. But the old ESP won’t work. So either I broke it, or it was broken from the start.

  10. Dêe Vázquez says:

    Hi guys! I followed the tutorial but when it comes to upload the program I keep receiving the following message:

    “Arduino:1.6.3 (Windows 7), Placa:”Generic ESP8266 Module, 80 MHz, 115200”

    Cannot run program “C:Program Files (x86)Arduino/hardware/tools/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++”: CreateProcess error=2, El sistema no puede encontrar el archivo especificado

    This report would have more information with
    “Show verbose output during compilation”
    activala desde Archivo > Preferencias”

    Sorry, my version is in spanish…

    Can anyone help me?

    Thanks!

    1. Dêe Vázquez says:

      “Finally select “esptool” from the Tools → Programmer menu.”
      Actually I don`t have that option on the programmer menu. What could be the problem?

      1. Dêe Vázquez says:

        OK..I re-downloaded the library and have the “esptool” on Tools-> Programmer. But got an “Compilation Error”

        1. Dêe Vázquez says:

          OK, so I`ve tried with the 3 versions on gitHub. None worked. I finally got a simple Compile Error and that was it. Could it maybe my Arduino IDE version? I`m using the 1.6.3 on Windows 7. It`s maybe a silly question but I don`t know what more can I do with it.

          1. Doug Strickland says:

            The version on the github is a fork called 1.6.1, the last “common” release before arduino.org (The LLC) forked it for the release of the new Arduino Zero. When you are running the correct ide (after downloading it from github) – you should see [sketch name] | Arduino 1.6.1 in the header.

          2. Alasdair Allan says:

            You need to use the specific version of the IDE linked in the post. It’s a custom fork of the Arduino IDE with support for the ESP8266 built in…

          3. Dêe Vázquez says:

            OK! Thanks for the answer. I`ll do that

          4. Ronald Golec says:

            Hi Dee,

            I’m using OS X 10.10.3 with Arduino IDE 1.6.4. After installing the ‘esp8266-Arduino-0.0.5’ library inside my hardware folder, I do not see the “esptool” inside Tools-> Programmer.

            Did it work for you? If yes please let me know how. Thanks!

          5. Dêe Vázquez says:

            Hey Ronald. I managed to make it work following Alasdair instructions: “You need to use the specific version of the IDE linked in the post. It’s a custom fork of the Arduino IDE with support for the ESP8266 built in”.

            The modified version can be found at the begining of the article. It instals as normal. Or at least I had no problems with it. Actually I did not have to install the harware because it already came with the very cool modified version. Take a closer look at the begining of the article you will find it.

            Cheers

          6. Ronald Golec says:

            Hi Dee, thank you for the feedback. I downloaded the modified version from Github, I searched inside all the folders, however I cannot locate the OSX version of the modified Arduino IDE application.
            Can you please indicate where its located? Thanks.

          7. Ronald Golec says:

            Hi Dee, thank you for the feedback. I downloaded the modified version from Github, I searched inside all the folders, I cannot locate the OSX version of the modified Arduino IDE application.

            Can you please indicate in which folder the IDE is located? Thank you.

          8. Dêe Vázquez says:

            Hi Ronald. I know only what`s here. I suppose you looked inside the second folder in this link right?

            https://github.com/esp8266/Arduino/releases

            Because for me with Windows, it was a straight foward install once I understood it was just install a hole “new” IDE in the computer. But that`s as far as I go. I sugest you ask the author of the article as I did.

            Cheers

          9. Ronald Golec says:

            The ‘releases’ link… but of course! …embarrassed, newbie to github. Very straightforward indeed! Thanks again, much appreciated.

            Cheers

          10. Dêe Vázquez says:

            I think for you it should be this: “I’m on a Mac, and at that point it comes down to downloading the pre-built binary* release from GitHub. The custom binary will live quite happily …”

          11. Dêe Vázquez says:

            Sorry, I`m a newbie, obviously

            “Installation of the custom build of the Arduino IDE really couldn’t be simpler. I’m on a Mac, and at that point it comes down to downloading the pre-built binary release from GitHub.The custom binary will live quite happily alongside your existing stock
            Arduino development environment — in fact, as well as the ESP8266 build,
            I think I’ve got six or seven other versions of the environment
            installed at the moment, with version numbers ranging from 1.0.x up to
            to latest 1.6.x build.”

            Which one is the one should I download? And than..is it a ordinary instalation? Thank you!! And sorry if these are silly questions but again I`m new on this hole thing

          12. Ronald Golec says:

            Hi Alasdair,
            how do I apply this modified version of the IDE with ESP8266 support to my existing Arduino IDE v1.6.4 on OSX?

          13. Eugene Goostman says:

            You can install the ESP using the board manager in 1.6.4

            This details the process: https://github.com/esp8266/Arduino

          14. Alasdair Allan says:

            Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. There are ESP8266 packages available for Windows, Mac OS, and Linux (both 32 and 64 bit).
            Install Arduino 1.6.4 from the Arduino website.

            Start Arduino and open Preferences window.

            Enter http://arduino.esp8266.com/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.

            Open Boards Manager from Tools > Board menu and install esp8266 platform (and don’t forget to select your ESP8266 board from Tools > Board menu after installation).

        2. Brendan Matkin says:

          You might also consider this version if you are still having trouble: https://github.com/sandeepmistry/esp8266-Arduino

          Instead of installing a new IDE, you just install it as a new piece of hardware (the instructions are in the README and are very easy – basically the same as installing a library). Make sure if you go this route to go back to the official, most recent Arduino IDE (1.6.3): http://www.arduino.cc/en/Main/Software.

    2. Tarun Vaghasia says:

      Re install the board from tools menu .

  11. Samira Samilan says:

    question to the auther:
    Could you explain which part of the code handles http://gpio/1 or http://gpio/0 ?
    I tried to follow the code and I could not figure it out. Thanks.

    1. Alasdair Allan says:

      That’d be this bit…

      // Read the first line of the request
      String req = client.readStringUntil(‘r’);
      Serial.println(req);
      client.flush();

      // Match the request
      int val;
      if (req.indexOf(“/gpio/0”) != -1)
      val = 0;
      else if (req.indexOf(“/gpio/1”) != -1)
      val = 1;
      else {
      Serial.println(“invalid request”);
      client.stop();
      return;
      }

      // Set GPIO2 according to the request
      digitalWrite(2, val);

      1. Alasdair Allan says:

        Here it takes the request string ‘req’, matches whether we’re toggling gpio_2 to 0 (low) or 1 (high) and sets the variable ‘val’ accordingly. Then it uses digitalWrite( … ) to toggle the pin.

  12. Aluminium says:

    Here an adaptation of the ESP8266 to directly fit the arduino board: https://www.youtube.com/watch?v=s5vnUyBnkiU

    1. Punith R Puni says:

      Please tell me how to change the name of the WIFI Module.Every module appears by the name EX:ESP_8732GA . I want to change this to other name. How can I Please Help?

  13. djw says:

    Hi Alasdair,

    I am a newbie in this area, but thanks for showing the rope. If I may ask, instead of using a FTDI friend or a FTDI cable, can I use USB cable to power Arduino and use Arduino’s 3.3V/GND for power and ground, Arduino’s TX/RX to ESP8266’s RX/TX?

    1. Alasdair Allan says:

      Yes, but only if you’re using the ESP8266 as a Serial device for the Arduino. You won’t be able to flash code onto the board using this method.

      1. djw says:

        I see. Thanks!

  14. John says:

    Hi there. I managed to upload the sketch, but when I open the serial monitor it said “Connecting to 4MACUM.1xg45
    ……………………………………………………………”, but it just prints dots, and I never see the “WiFi connected” message.

    My password is 63 characters long and contains all kind of strange simbols like @#>{}$. Could the password be the problem or is there something else?
    Thanks.

  15. Majenko Technologies says:

    Tired of the primitive Arduino IDE? The ESP8266 modules are now fully supported by the more advanced, universal, UECIDE environment. Program the ESP8266, and all your other favourite boards, in comfort. http://uecide.org

  16. Tarun Vaghasia says:

    My terminal gives me random output after uploading the example.I also changed the SSID and password.

    1. Eugene Goostman says:

      What speed is your terminal session – all the boards I have used so far are at 9600.

      There are also two variants of firmware – NodeMCU and ‘AT’ – the NodeMCU is an interpretive version of the Lua programming language and is very flexible. The AT is more basic.

      Personally, I only use NodeMCU now, although re-flashing firmware is very straightforward, and as it’s all open-source, you can write custom firmware if you want.

      Lots of info at http://www.esp8266.com/

      1. Tarun Vaghasia says:

        Can you please tell me how to upload lua script on esp8266?
        should i have to upload any firmware for uploading the lua script on esp?

        1. Eugene Goostman says:

          Get ESPlorer: http://esp8266.ru/esplorer/

          It makes it so easy.

          If your board has NodeMCU firmware, it will understand Lua.

          If not, you will need to load the firmware using the well-documented methods of loading firmware on an ESP.

          You can get NodeMCU firmware from nodemcu.com

  17. Tarun Vaghasia says:

    Can i use the same code for ESP-12?

    1. Eugene Goostman says:

      The ESP ‘numbers’ are just different packaging variants of the same processor.

      So yes, code for an ESP-01 will run on an ESP-12, ESP-07, ESP-03, etc.

      But… the pinouts/pads aren’t the same, so you may need to alter the code to take account of the different board layouts.

      Personally, I use ESP-07 now, as they have nearly as many pinouts as the ESP-12, and the option of built-in chip antenna or off-the-board U-FL antenna, with more range.

  18. Anderson Wang says:

    Hi
    ALASDAIR ALLAN,
    Thanks for the good writing. I did all steps and were able to upload the bins to ESP8266. But when I ran all three examples, WiFiClient, WifiScan and WiFiWebServer, using the Arduino Serial, the output are all Greek to me. Can not read. I removed the GPIO 0, floating.

  19. Anderson Wang says:

    Just to the specific step that I encountered the unreadable on Arduino Due serial monitor. I did not see text message like Connecting to Wireless Network at all. Thanks

    Now go ahead and open the Serial Monitor, remove the jumper between the GPIO_0 pin and GND, you toggle the power to the board again. If you do not toggle the power to the board at this stage, you sketch won’t be loaded.

    However if all is still going well you should see something like this,

    Connecting to Wireless Network
    …….
    WiFi connected
    Server started
    192.168.1.224

  20. Anderson Wang says:

    I finally got it to work. The issue had a lot to do with the baud rate. At the esp8266 start up time it spill out a lot of garbage characters and MEM CHECK FAIL!!! messages. I thought that was bad. If you are patient enough you will eventually see these messages. Set Serial Monitor baud rate at 115200 regardless.

    Connecting to Wireless Network
    …….
    WiFi connected
    Server started

  21. satya sankar says:

    how can i find mac address of esp8266? any command or sample api code? Thanks

  22. John Anderson says:

    I am trying to get this running for the first time. I achieve network connection and see the IP for my ESP8266. But when I do http://gpio/1 in my Chrome browser I don’t even see the “new client” message. Also, I can’t ping the IP successfully from my computer. I can ping OK from my wife’s computer in the kitchen, but still can’t do the http://gpio/1 successfully. I tried putting the ESP8266 in the kitchen and pinging from my PC, but still no luck. Can you help?

  23. tahnok says:

    Great tutorial! Just a note

    **YOU DON’T NEED TO SELECT ESPTOOL AS THE PROGRAMMER ANYMORE** on Arduino 1.6.4 (see https://github.com/sandeepmistry/esp8266-Arduino/issues/2)

  24. Jupiterov says:

    There is an amazing new project based on ESP8266 that permits to control Arduino with smartphones, where Arduino can completely draw the graphical interface. It’s very powerful. With a single line of code you can draw panels with LEDs, buttons, plots, sliding bars, pictures, switches… the project website is http://www.miupanel.com , there are examples that show how to control a Relay via Internet, implement a multichannel voltmeter and even an oscilloscope with Arduino UNO

  25. Anderson Wang says:

    Yes, it is a good one. But there may be capacitors and resistors you need to install to get rid of noise from power line and things like pullup and pulldown. I have set up a web server as backup links to my other Arduino AT Mega 2560 web server. You can also have an AT command server to link to other web site to retrieve information.

  26. oded duxi says:

    hi, in the drawing it seems like the Tx and Rx are connected to +5v FTDI output, it means that 8266 will get +5v in its Tx an Rx inputs, wouldn’t that damage it as it supports only 3v?

  27. Harriesh Gomahan says:

    Great Tutorial .. But I have one doubt assume instead of LED light I want a sensor in that place. Do will i need Audrinuo UNO and if so how to connect them here ?

  28. Wael Hossam says:

    Hello, I just did it all and I can see in my Arduino IDE the ESP8266 board but I cannot find “esptool” in the Tools / Programmer menu. What should I do?

  29. Gregg Levine says:

    Now here’s an idea: What about making all three parts available as a PDF?

  30. Gregg Levine says:

    I didn’t notice it until just now, there’s a nice typo on the page. The word “board” is misspelled, with the “o” and the “a” swapped.

    1. sophiacamille says:

      Thanks for the catch! Updated. I wish all typos were nice typos :)

      1. Gregg Levine says:

        We all do when in comes to magazine articles. Your welcome.

  31. Brian van Vlymen says:

    How you do command if Serial.println(WiFI.localIP()) is not working on Serial Monitor?

  32. Stephen Griswold says:

    Just noticed, the link to Sandeepmistry’s github is broken.. is there a more recent version?

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
Tagged

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

View more articles by Alasdair Allan

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK