ESP8266 a Complete Beginners Guide (IOT)
by kmanchanda in Circuits > Arduino
52439 Views, 158 Favorites, 0 Comments
ESP8266 a Complete Beginners Guide (IOT)







I am making this instructable after my long 2-day struggle with ESP866. Since the day it arrived , to this day , I have surfed through nearly 50+ websites , blogs, instructables , data-sheets . In middle of all this I decided to make my own INSTRUCTABLE for other people who would like to be a part of this wonderful family .
(Yes I used the word family, IOT is a family )
CRUX of this instructable:
1. About ESP8266 .
2. How to start ESP8266 ?
3. Flashing and Programming ESP8266 .
4. Basic Blink Example controlled via Mobile .
Note to the readers : I added this instructable in various Contest , so if you like what you read please VOTE .
Winning a contest will help for further development and experimenting .
If you have read this far :READ MY COMPLETE INSTRUCTABLE AND I ASSURE YOU , IT WILL MAKE YOUR LIFE EASIER .
Questions and Queries are welcome , feel free to drop a message ( with some love , hehe )
Let us start -
- What is ESP8266 ?
- The ESP8266 is a low-cost WiFi chip with full TCP/IP stack and MCU (Micro Controller Unit) capability produced by Shanghai-based Chinese manufacturer, Espressif Systems.
- OR It is just a WiFi module which can be used with other Electronic Platforms . You can relate to it as the WiFi which is present in your Laptops , Smartphones , Tablets , etc . It has a 4 MB Flash memory which can be used to store programs .
- Over the years there have been many advancements on ESP8266 and there are many different modules of the same. Since I have the ESP-01 module only I will discuss it , also it is not breadboard friendly so therefore we have to use Male to Female headers / PCB with Female headers for ESP and Male Headers for breadboard .
-
The BEST PART is it is very cheap starting from $3 .
-
It can act like AP(Access Point) or connect to AP or Both .
-
It can be used in Home Automation devices .
-
It can very well receive commands via the internet or local host.
-
It can act like an ARDUINO .
-
The ESP8266 is also faster and stores more than the Arduino , the only con is with the ESP-01 since it has only 2 GPIO pins ( General Purpose Input Output ) , for which you can use ESP-12.
Working of ESP8266 :
- First we connect and set-up the environment required for ESP8266 , that is through the Arduino-IDE . Nowadays there are may different platforms to run ESP8266 , but since Arduino is universal , we will use that.
- The ESP8266 needs to be flashed with a firmware which will host the program . In this too there are many different firmware(s) . And it needs to be put into Flash mode before flashing.
- After Flashing we upload our program in the same way like an Arduino but with a small catch that the ESP8266 needs to be put into Bootloader mode before uploading .
- Saving the program on the ESP8266 so that it does not reset after restarting .
- Last but not the least ONLY 3.3V and NOT 5V .
*************************************************************************************
WARNING : WORKS ONLY WITH 3.3V AND NOT 5V . ESP8266 WILL PROBABLY FRY AT 5V .
ENSURE TX ,RX , Vcc ARE AT 3.3V BEFORE CONNECTION .
*************************************************************************************
Collect Material
















The basic question is what all is needed to use this great tool . I will also lay out all the alternatives I have read so far which are used to program ESP-01 (ESP8266) .
- ESP8266 module . I will use ESP-01 .
- A 3.3 Volts power supply
or 5 volt to 3.3 volt DC-to-DC converter
for standalone ESP projects or AMS1117 or LM1117 converters(LD33 ) .
- Arduino UNO or any other Arduino , with wire ( With or Without the IC )
- Female to Male , Male to Male Header wires .
- Breadboard mini or general 850 Point one ( Basically any Breadboard ) .
- If you don't have or want Arduino , You can use a FTDI or USB to Serial TTL CP2102 adapter .
NOTE : Basic thing to understand is that the ESP can be powered with Arduino or the CP2102 adapter while programming , but for standalone projects we need a solid power supply at 3.3 Volt and 500mA .
*************************************************************************************
WARNING : WORKS ONLY WITH 3.3V AND NOT 5V . ESP8266 WILL PROBABLY FRY AT 5V .
I don't take responsibility for it.
*************************************************************************************
Basically it needs only 3.3V and Maximum of 800mA at peak and Minimum 250mA to operate .
I have attached a PDF from the ESP8266 Community Wiki that is a datasheet of ESP8266 .
I will be using this Freeduino ( Similar to Arduino ) to program the ESP-01 , since I don't want to remove the IC from my new UNO .
Downloads
Setting Up Environment for ESP8266






Setting up the Environment .
Software Arduino Environment v 1.6.4 or greater
Installing with Boards Manager Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager.
It have packages available for Windows, Mac OS, and Linux (32 and 64 bit).
Install Arduino 1.6.4 (or greater) from the Arduino website ( I have 1.6.11) . Start Arduino and open Preferences window.
Enter http://arduino.esp8266.com/package_esp8266com_ind... 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).
Procedure:
Start Arduino 1.6.4 or Higher
Select ‘Tools’- ‘Port’ whatever # your USB-serial is on
Select ‘Tools’ -‘Board’ ‘Generic ESP8266 Module’
Select ‘Tools’- ‘CPU Frequency’ ‘80MHz’ or Overclock afterwards at '160Mhz'
Select ‘Tools’ -‘Flash Size’ ‘512K (64K SPIFFS)
Select ‘Tools’ -‘Upload Speed’ ‘115200’ for ESP 12E , also Some ESPs may be 9600
Connecting ESP8266 With Arduino or USB to Serial





CONNECTIONS
The Connections are ( For ARDUINO ) :-
Firstly Remove the Atmega Chip from the Arduino
- Vcc and CH_PD ( ENable) to 3.3V on Arduino
- GND to Ground . ( For ESP -12 , GPIO15 to GND as well )
- Tx to Tx of Arduino
- Rx to Rx of Arduino
- RST , GPIO0, GPIO2 are floating ( Neither High nor Low )
Important part here is the ESP uses more current than the Arduino , thus at risk .
Therefore I use and external DC 12 V , 1 A beside the PC connection .
For other connections refer the Images .
Checking the Connections

Before flashing lets check the connections
The ESP modules usually come with a built in AT Firmware by the Ai-Thinker .
So refer to this Image for commands .
Open up the Arduino , Go to the Serial Monitor ( Do select your COM port ) and Write :
AT
// This should return OK , else it's not working
Possible Errors :
- Check connections
- Select proper Baud Rate
- Arduino COM port is correct
- The Red LED ( ESP 01 ) is Bright (High )
If none of these work Pray to God .
Some Commands :
AT+GMR = to check firmware version
AT+RST = Soft reset
AT+CWLAP = Find Nearby Wi-Fi
AT+CWJAP = Connect to a specified AP
NOTE : If you are trying to connect to any wifi using AT+CWJAP and it returns ERROR or just sits there
Follow these commands :
AT+RST
AT+CWJAP=" "," " // ( This should return Error or OK, it's fine )
AT+CWJAP? // No AP or Error , Still Fine
AT+CWJAP = "Your SSID","Your Password" // THESE ARE CASE SENSITIVE
ALTERNATE TO AT command from ARDUINO :
There is this Java Software : ESPlorer , a wonder to use .
I have uploaded this also in the ZIP file .
Flashing Your Own Firmware



Now the main step ,
The ESP can be programmed by various methods .
There are many Firmwares for it like the NodeMCU , ESPBasic , Arduino , etc
The NodeMcu runs on the LUA script ( Out of my expertise as of now )
But Arduino still runs on C++ ( In my expertise )
So we will Flash a firmware which will make the ESP to take the Arduino Script (Cpp script ) and run it .
Softwares available :
- ESP8266 Flasher
- NodeMcu's own Flasher
- ESP Flash Download Tool
- Another ESP flash tool
In my Quest ( To flash ESP 12E ) , I learnt and tried mostly all of them .
I made a zip file for all the different tools I have used .
Now to the main part ( Using the ESP8266 Flasher )
- Open ESP8266 Flasher
- Select the COM port ( Very Important )
- Select the BIN file , i.e your Firmware file
- Take GPIO0 to GND ( RST and GPIO2 are floating )
- Select 0x00000
- Hit Download
- The Blue Led starts to Blink fast
It will start to Erase and Write firmware ( 0 to 99% )
And will end at saying Unable to leave Flash mode , Don't worry it's perfectly fine.
THE BIN FILE is in THE ZIP ( v0.9.2.2 AT Firmware.bin ) Use this .
Possible Errors :
- GPIO0 is not grounded
- Loose connections
- COM port is not correct
If nothing works , restart your ESP and Take the RST ( Reset ) to Gnd and remove
Let the blue Led flash once and try again from the start
Downloads
Uploading an Arduino Program (Final )


These instructions are available everywhere but the most important part here is to put the ESP module in Bootloader mode before uploading .
Firstly select The correct Board - Generic ESP8266 module
Then the COM port
Open any program in Arduino , let us say Blink .
Change pin 13 to 2 , and use a LED and Upload
Now before hitting Upload , take Gpio0 to ground
And RST to ground afterwards , Remove RST after half a second ( The blue led flashes for some millisecond )
Take GPIO0 back ( To high or Float )
Hit Upload , the blue flashes once and then blinks till it gets uploaded .
Now you are all done . Remember before uploading put ESP in Boot Mode .
Thanks
Thanks for reading and If you have any queries just comment below , Very Happy to Help .
P.S : If you are looking for serious home automation , Try using NodeMCU or ESP-12E or 12F .
Since they have More GPIO pins .
If I helped you in any way , do hit on that little heart , means a lot to me .