Introduction: ESP8266 Easy Setup With Arduino and Stand Alone
I got my hands on one of these modules with the intent of setting it up as a WiFi link to my network. While there is a LOT of information on the internet on how to use these, after reading dozens of guides, with some conflicting the information given by others, I decided to create a guide for using these.
Disclaimer : I Do work for Proto-PIC.co.uk and this is where I will supply links to for hardware.
I am running ARDUINO IDE V1.6.5 r2 on Windows 7 (64 bit).
Other software required :
Download both of the above files, and extract them to a memorable location (I'll refer to this location as NODEMCU from now).
Hardware required :
A 3.3V Power Source, capable of supplying at least 300mA ( Pololu 3.3V regulator D24V3F3 )
A Breadboard ( I also added a capacitor to the power rails - 100uF Electrolytic).
A 100uF Electrolytic Capacitor (For the RESET line).
2 x CD4050BE Non inverting Buffer Chips (or another way to convert logic levels).
Step 1: Update the Default Firmware on the ESP8266
The ESP8266 has eight pins, as shown above, to upload the new firmware we need to connect the module as follows :
GND - Create a common ground on your breadboard and connect this to it.
VCC - Connect to the 3.3V output from your voltage regulator.
CH_PD - Also connect to 3.3V output from your voltage regulator.
Tx - Connect to Rx on the FTDI Board (Make sure this is set to 3.3V).
Rx - Connect to Tx on the FTDI Board.
RST - Connect to one side of the Electrolytic capacitor, the other side goes to DTR on the FTDI BOARD
G0 - Connect to GND for updating the firmware.
When you have all the leads connected and checked, connect the 5V OUT from the arduino to the IN on the voltage regulator, and connect the Ground from the Arduino the the Ground on the regulator. Plug your Arduino and the FTDI USB cables in. you should have a RED LED on the ESP8266, a GREEN LED on the Arduino, and no LEDs on the FTDI board (They may flicker when first plugged in). If you don't have these LEDs lit, then unplug and double check your connections.
You now need to open the NODEMCU Software. When you have it open you will get a screen like the one above. Select whatever COM port your FTDI is on, and then click Config - Click the gear on the first line & select the .bin file you downloaded. Make sure the rest of the tick boxes on the left hand side have no 'X' in them & that the first one does. Choose the offset to be 0x00000 in the top right drop down box. Click the Advanced tab and click on the 'Restore default' button. Now click the Operation tab, then the 'Flash' button, This may take a while to flash the firmware, but when it is complete, a green tick should be shown in the bottom-left corner of the box.get this, disconnect the connection from G0 to ground and power cycle the board. Your board now has the updated firmware.
Step 2: Testing the Update.
Now that the ESP8266 has the firmware updated, we can test it and verify that it is working. If you open a terminal monitor program, and connect to the Serial port that has been assigned to the FTDI board, set the speed to 9600, and connect, you should be greeted with a line of gibberish, followed by a message :
[System Ready, Vendor:www.ai-thinker.com]
This shows the firmware has been uploaded successfully and is now running. Next to check the ESP8266 is accepting commands, type AT in capitals and press SEND or return to output this to the ESP8266. You should get a response of OK . If not, you may need to change the settings of your Terminal program to output a New Line and Carriage Return at the end of a line.
Now follow the following steps (If you get errors, just retype the command)
Response : OK , followed by garbage and [System Ready, Vendor:www.ai-thinker.com]
Response : OK or no change
Response : A list of access points within range :
where the values are (Encryption type,SSID,Strength of Signal,MAC,Channel)
Response : OK
Response : OK
Response : OK
Response : 2 IP Addresses, The default Access Point (192.168.4.1) & another.
The other is the address to point your browser to.
When you connect with your browser, you should get an output similar to this in your Terminal Monitor:
+IPD,0,287:GET / HTTP/1.1 Host: 192.168.1.150 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive
You have now configured the ESP8266 to be a server & showing responses to requests from requests.
You can stop the ESP8266 echoing the input if you enter ATE0 (Re-activate with ATE1)
Step 3: Arduino As a Web Server With the ESP8266 As the Access Point
The ESP8266 has now been tested, we now need to use the Arduino to serve pages based on the connection request from a browser. The ESP8266 is a 3.3V device & requires level shifting for the data lines, as the Arduino UNO runs its IO Pins at 5V.
Th image above shows the standard Transistor circuit used to make a one channel Level converter.
When you have Ground, Tx and Rx connected to the Arduino and a 3.3V supply going to the ESP8266 module and Logic Converter circuit, you are ready to go.
Download the INO file and open it in the Arduino IDE, upload it to your UNO & when complete, open the Serial monitor at 9600 BAUD. You will get an output with confirmation of each step from the ESP8266 module. When you have the IP address (NOT the 192.168.4.1) - connect to this address with your browser, you should get a page with a hello world message and a button (Does nothing at the moment).
Congratulations - you have set up an arduino as a wireless web server
You can now have the Arduino with an ESP8266 running as a server anywhere you can get power, ideal for using as a sensor server in that difficult to reach place e.g. the far corner of an attic where you need to monitor Temperature and Humidity.
We have a be nice policy.
Please be positive and constructive.