Things used in this project
|Software apps and online services:|
I was asked (by member F.G.M.) to create a project using the ESP8266. He asked for connectivity to the Internet, Arduino IDE, and using I/O. This project is a skeleton project that anyone can utilize to get started with the WiFi device. Upon powering up, the ESP8266 will initialize the SSD1306 (I2C) OLED, will scan all surrounding networks looking for the specified "home" network, and upon finding the home network, will attempt to connect and log-in to the WiFi router. At the end of this process, the OLED will show the DHCP assigned IP address for the device. If you are a skeptic, you can open up a console window and PING the device!
Understanding the programming environment
Basic Concept #1:
The ESP8266 when used with the Arduino IDE becomes just another Arduino Board, in this case a board similar to the Pro Mini - a small board with a serial UART but without USB capability. Therefore, to connect to the board, the user must have a serial-USB module. I will list one in the parts list, but you must select one that is 3.3V capable.
Do NOT confuse this with an ESP8266 running in "AT" command mode talking to an Arduino board programmed to handshake with the ESP8266. Some online articles make it difficult at first to distinguish the configuration.
Basic Concept #2:
The ESP8266 has both flash and static-RAM (SRAM) memories. If the code you write in the Arduino IDE is downloaded into a stock Arduino (UNO, Mini, Nano, Mega2560, Adafruit Pro Trinket, etc.) then you are handshaking over the serial link to the ESP8266; the command set is most likely "AT". The "AT" methodology is command/response and very similar to the old Hayes modems of the dial-up era. One problem with command/response use is that the programmer must plan for every possible response coming back from the ESP8266 which can be very taxing and could change with the next module purchased if it has a different firmware version.
When you receive your board, you may have firmware pre-installed that defaults to 115200 bps or your device may have firmware that connects at 9600 bps by default. Try the faster speed first, then the lower speed. And to complicate things even more, there are a variety of ESP8266 boards available (and more planned.)
Basic Concept #3:
To use the Arduino IDE to directly program an ESP8266, one must have the Arduino software on a workstation (PC, Mac, Linux) and one must install the ESP8266 "core" files. The exact methodology used will depend upon which core you install (there are several) and which version of Arduino you are using (there are many.) Distilled to the most common, there are three Arduino IDE versions and two cores which will likely cover most situations:
I have tested with both of the above on Windows 8.1 Pro. You only need to select one "core" set from the below for your use - read on.
Software "core" installation: To complicate things even more than the above choices, there are two installation methods for #1 and #2 cores shown above! The method will depend upon which core and which version of the Arduino IDE you select. If you are running 1.6.4 or higher from Arduino.cc, then you need to install the new core using the Board Manager method described here.
If you are using any other IDE, from Arduino.org or any version lower than 1.6.4 from Arduino.cc, then you unzip and download the #2 core identified above and unZIP the files into your working Arduino directory, in the hardware folder. On my workstation, this appears as: \Documents\Arduino\hardware\ESP8266 The basic instructions to follow are located here.
Making the connections: ESP8266-01
On a breadboard: (snipped from Google Images)
My test setup: In Pictures
Details of connections:
- The OLED is a 4-pin I2C device with SDA connecting to GPIO0 (zero) and SCL connecting to GPIO2 (zero 2).
- CH_PD is connected to Vcc 3.3V Some schematics show this connected to Vcc via a small value resistor but that resistor is optional in normal operation.
- RST (reset) should be pulled to Vcc using a 10K resistor
- Vcc and GND are connected to Vcc and GND of the OLED and then to a suitable, stable 3.3V source (battery, regulator, etc.) A 100uF capacitor of good quality should be across the Vcc and GND connections very near the ESP8266.
UTXD and URXD are the UART serial connections to the ESP8266, usually 115200bps or 9600 bps depending upon firmware version.
UTXD is an output so it should connect to RXD on the serial-USB module.
URXD is an input, so it should connect to TXD on the serial-USB module.
The Arduino flavor core seems to manage the ESP8266 well. Using a clean, stable power supply is key. Other things to note:
- DO NOT take GPIO0 directly to Gnd to activate program mode! Rather,
- power-off the ESP8266,
- pull-down to Gnd pin GPIO0 using a 330 Ohm resistor,
- remove the GPIO0 from the pull-down and connect as sketch required (OLED)
- The 330 Ohm resistor will prevent any damage to the uC should the pin be driven accidently to a HIGH state.
- * ONLY use a 3.3V serial-USB module. Never use a 5V serial converter. Do not attempt to power the ESP8266 from the 3.3V output of a serial-USB adapter as the '8266 simply requires too much current. Batteries or a well designed 3.3V supply is required.
- Use a quality electrolytic as close to the ESP8266 board as practical... I'm using 100uF
- Do use 1.8K Ohm resistors to 3.3V as I2C pull-ups
The Sketch Code
Place the un-ZIP'd code all into a single folder: this is a multi-tabbed project! On my computer, the path is:
In closing, I want to just say that I classified this as an Intermediate Project but the ESP8266 can be very frustrating, so I do not recommend to Beginners. There are some YouTube videos available and numerous Internet resources, but much of the information is wrong! If you undertake this project, give yourself some extra time and if you become a bit frustrated, take some time away. The ESP8266 can be "smoked" in an instant and while not terribly expensive, seeing your $4 - $5 little board fried before your eyes is painful when you know that next boat from China will take a few weeks to arrive.
As always, have fun.
Main ESP8266.com core
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!