Arduino and Sparkfun ESP8266 WiFi Shield

The Sparkfun ESP8266 WiFi Shield arrives as-is:

If you, like me, forgot to order the Stackable Header kit - R3, you either go rummaging around boxes of stuff (or even in the "man drawer") else you get online and order them and have to wait even longer to get up and running.  Fortunately, as usual, I had some "spare parts" from previous over-ordering.

Once I'd dug out the soldering iron and soldered the pins to the board, it was a case of blowing off the dust from an old DFRobot RoMeo v1.1 Arduino board.
Now, I will say, you can use any Arduino UNO board and in fact most of the "proper" boards are much smaller than the RoMeo... So, why did I have the RoMeo boards in the first place?  Well, they have motor-controllers built into them, which means you can wire them up to servos and wheels and you only need the one board.  (There are newer versions now available that have integrated Bluetooth too).

Okay, I realise that there might be the odd person on the planet who does not know what an Arduino is, so here is a link to a page that will explain everything for you.

At the base, you have the Arduino board itself and you then plug "Shields" on top of the Arduino.  This allows you to stack multiple "Shields" on top of each other and provide you with the extra features that you want, such as having a WiFi Shield and an Interface Sensor Shield that allows writing to an SD card that also allows controlling a laser (yes, I do have some "proper" frickin' lasers on the bench).
Obviously there are restrictions on how many you can use at once.  The amount of PINs available, the power drain, the amount of space for the actual code itself to run on the Arduino, etc..etc.. but you get the idea.  "Shields" are a nice way to make modular things.  Plug'n'Play.

If you want to walk through the theory of Arduino Step by Step, then I would recommend taking this course.  Wow, £154....(I think I got a Coupon that allowed me to have a reduced rate)....but trust me, if you don't know what you're doing, you could EASILY spend >£150 on Arduinos and Shields and parts and end up with a load of kit that you can't make head or tail of.  The other option and sooooo 19th century, is to buy a book.  Yes, I just did say that.  Books are cool, but, they do go out of date pretty quick.  This type of OnLine course gets updated frequently, so if things change you get to know about the updates as you have Lifetime access.

Right, now the introductions are over, let's get into the real stuff.

I did find the Sparkfun Shield Hookup guide here, which was fine... but as with most technical things, it's makes more sense AFTER you've worked it all out (and probably broken the device and had to order another one).  In the guide they dive straight into the AT Firmware Overview information.  IGNORE THIS.  You don't need to know this.  Same goes for the Custom GPIO Commands.

I have the latest Arduino IDE installed, DOWNLOAD FROM HERE.
The Arduino IDE has some default Libraries installed, HERE explains how to add more Libraries for your platform.

For the ESP8266, you need a library to be able to communicate with it.  DOWNLOAD THE LIBRARY and just save it to the /Downloads folder.

Open a new Sketch, select 'Sketch | Include Library > Add .ZIP Library' and point it at the file you just downloaded into the /Downloads folder.  That's right, you don't even need to unzip the files anymore.  yay!

Now, if you select 'File | Examples', you'll see 'Sparkfun ESP8266 AT Library'.  If you move over this, you'll see some sample Sketches, select the 'ESP8266_Shield_Demo' sketch.  This will open in a new window.  The Arduino IDE let's you open multiple sketches at once, which is handy when you are merging multiple isolated bits of Shield functionality into a single sketch.

All that you need to change in this code is the mySSID[] and myPSK[] strings.  You just need to replace the values with your WiFi SSID and password.  The normal ones that you use from your tablet / phone or laptop.

That's it.  Well, you might actually want to understand the code itself, so flip back to the Sparkfun hookup-guide as they do a section entitled 'Using the ESP8266 AT Library' that shows the basics of what is needed.


Again, totally IGNORE the '(Re-)Programming the ESP8266' section, unless you are an uber-geek, you will never need to do this.  Seriously, it's like letting someone loose on recompiling the kernel of your laptop operating system,  there are few people who need to do that and if they do need to, they will not be reading this blog post :-)

Okay, back to the HARDWARE.

On the Sparkfun ESP8266 WiFi Shield itself, there is a UART SW<-->HW switch.  Make sure it is set to SW.

If you set this to HW and use pins 0 and 1 for TX/RX and you have the Shield powered up AND you press the 'Upload' button from the Arduino IDE.... the sketch will get uploaded INTO the WiFi Shield itself...and boom.  Dead Shield.  You've just overwritten the firmware.  Apparently, there is a way to recover from this, but I could not find it after 10min of Googling....

The safest thing I found was to disconnect the Power to the Shield when pressing 'Upload' from the Arduino IDE.
This way it always guaranteed that only the RoMeo was getting updated.  Once it was successful, I then powered up the WiFi Shield.

Also, make sure you connect PINS 8 and 9.  These are hard-coded in the library, so if you have anything else wanting to use these PINS change your code to use another couple of PINS.  Then it's just a case of connecting GND, 5V and RESET.  (In the photo I also have 3.3V, but this is redundant and was removed after I took the photo).

From the Arduino IDE, select 'Tools | Serial Monitor'.  This will display the DEBUG window where all of those Serial.print() commands are displayed.

When you start the WiFi Shield up, there is a BLUE STAT LED that will be flashing.  It will flash for a few seconds as it is attempting to connect to the WiFi Access Point that you entered into the code.  Once a connection is made the BLUE STAT LED will stop flashing and will be a SOLID BLUE.  You should then see an output in the 'Serial Monitor' something like this:

As you can see, I have been granted an IP Address from the DHCP Server running on my router.  I have connected to a domain '', I have received the response from the website and we are able to output the response.

The sample code also switches the WiFi Shield to be an Access Point, where you can publish some raw data, for example:

Okay, you maybe thinking, so what?  You can access a website and get the HTML/Javascript, but what use is that?  Well, think the other way around.  We can now POST to a website from the Arduino!

Think of this scenario....I have several Ultrasonic Sensors attached to my Robot.  They are attached to servos that periodically 'sweep' to the left and right of the robot.  The sensors are able to detect how far away any objects happen to be, for instance, a wall... or a cat.  We can record those detections either to an SD Card (eats up a lot of RAM using that library) OR we can collect a 10x10 Occupancy grid array and when it is full we can POST that data to a web-server on the internet.

Now, that web-server could be a Raspberry Pi running NGINX and NodeJS, with an exposed ExpressJS REST API...that can then save that 'mapping data' to a MongoDB that will then allow us to view in real-time the mapping of the environment around the robot...
(Replace Raspberry Pi with IBM Bluemix, etc..etc...etc...)

Oh and what-if, we can make the WiFi Shield operate in Access Point mode as well as Station mode (ESP8266_MODE_STAP).  We can not only POST data to a web-server/REST API.  We can RECEIVE data too....

We could use a library like this one: aREST to then allow controlling our robot remotely.  Whoa, now we can DRIVE the robot remotely, get SENSOR feedback informing us of the environment and we can avoid objects and navigate around.

To make this really cool, someone could have also purchased a PIXY Object recognition camera.

Now we're getting closer to the robot being a bit more autonomous.  Using the PIXY, the robot will be able to 'make decisions' for itself....

Further updates will be posted about my Robot adventures.  One day, I'll have my Huey, Duey and Leuy...

(Oh, so that's why Suzanne is learning how to use Blender 3D and you guys are looking at purchasing a 3D Printer.......  !!!!!)


  1. hi welcome to this blog.really you have post an informative will be really helpful to many peoples.thank you for sharing this blog.unix training in Chennai

  2. hi, can i ask if this library can be used to other esp8266 wifi shield (esp 11) ? big thanks sir!

  3. Here's the library source:

    looks like it might be specific to the Sparkfun hardware itself, but as it's open-source you could just give it a try and see what happens.

    Here's more info about the various esp8266 devices out there:

  4. thank you sir! by the way do you have any tutorial how will i used the esp8266 wifi shield as ap and a station? i'm trying to build a controller via wifi without the use of internet. can you give me some basics? i am new to this things. thank you sir!