Guru (talk)


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

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.

File-preference.png

Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Boards Manager URL's field under preferences as shown below.

Preference json.png

Next, Select the Board manager under Tools.

Board manager.png

Next, use the Board manager to install the ESP8266 package.

Install esp8266.png

Restart the Arduino IDE and Select the specific Board.

Board selecting.png

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);
}
</systaxhighlight> 
 
== 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? 
[[File:Wifiscan.jpg|thumbnail]]
 
{{DISQUS}}