Arduino Support for ESP8266 with simple test code
Guru (talk) 14:09, 15 October 2015 (IST)
ESP8266 packs a lot of punch. It is not just a WiFi module, it also has a decent micro-controller in built. Now the best part is the community has made programming this inbuilt micro-controller extremely easy by adding Arduino support. In this small tutorial, I will show you how easy it is to add Arduino Support
Contents
- 1 Arduino support for ESP8266
- 1.1 Download Arduino IDE from Arduino.cc ( 1.6.4 or greater)
- 1.2 Install the ESP8266 Board Package'
- 1.2.1 Select the Preferences under File.
- 1.2.2 Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Boards Manager URL's field under preferences as shown below.
- 1.2.3 Next, Select the Board manager under Tools.
- 1.2.4 Next, use the Board manager to install the ESP8266 package.
- 1.2.5 Restart the Arduino IDE and Select the specific Board.
- 2 Test Example
Arduino support for ESP8266
Download Arduino IDE from Arduino.cc ( 1.6.4 or greater)
https://www.arduino.cc/en/Main/Software
Install the ESP8266 Board Package'
Select the Preferences under File.
Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Boards Manager URL's field under preferences as shown below.
Next, Select the Board manager under Tools.
Next, use the Board manager to install the ESP8266 package.
Restart the Arduino IDE and Select the specific Board.
Test Example
To program ESP8266, you need a USB to serial converter. Image below shows connections made from Explore USB to Serial and Explore Wifi boards. Note that the Explore Wifi board has on board 3.3v regulator and circuitry to reset the board and put it in programming mode.
Test Code
I have used the sample code below to scan and display the available WiFi Networks.
/* * This sketch demonstrates how to scan WiFi networks. * The API is almost the same as with the WiFi Shield library, * the most obvious difference being the different file you need to include: */ #include "ESP8266WiFi.h" void setup() { Serial.begin(115200); // Set WiFi to station mode and disconnect from an AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); Serial.println("Setup done"); } void loop() { Serial.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) Serial.println("no networks found"); else { Serial.print(n); Serial.println(" networks found"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(")"); Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); delay(10); } } Serial.println(""); // Wait a bit before scanning again delay(5000); }
Output
Once you upload the program, you should be able to see the WiFi networks available at your place. If you don't have one, what will you connect your ESP too?