Node MCU ESP8266 wifi programming from Arduino IDE

This figure shows the corresponding Arduino Digital output pins on the right.
Source: https://www.youtube.com/watch?v=BbiLBiFvlsI

This is perhaps the cheapest configurable wifi board one will get (~$4 ~ZAR80) to program Arduino based code into.

To get started with this board, you will have to have done the following:

  • Installed usb driver for Silicon Labs CP210x USB to UART Bridge
  • In Arduino IDE>File>Preferences> pasted this link as boards manager: http://arduino.esp8266.com/stable/package_esp8266com_index.json
  • Installed the ESP Boards package via ArduinoIDE>Tools>Board>Boards Manager> Then search for ESP8266 package and install it.
  • Successfully connect the board via USB (with appropriate USB cable not only a USB charging cable, as some usb micro cables are only for charging, i.e. they only have the GND and +5V wires and do not include the communication wires / connections in the cable).
  • Note the connected COM Port of the board in >Device Manager.

Voltage control is 3.3V-based via an AMS1117 – 3.3

ADC0 (A0) is the only Analog (input) pin. Its maximum voltage is 1.0V.

For programming, use:

  • Board: NodeMCU 0.9 (this version worked for me, but others suggest 1.0)
  • Flash size: 4M (3M SPIFFS)
  • Upload speed 115200
  • Port: Com Port as identified in Device Manager
  • Programmer: usbasp
  • CPU freq: 80 MHz

To include wifi:

Begin the code with #include ESP8266WiFi.h, this library is apparently included in the main ArduinoIDE.

Define SSID and password:

Fig. 2. Defining the SSID and password.
Fig. 3. Defining what to do in the void setup() portion of code to initiate a wifi connection.
#include <ESP8266WiFi.h>
char ssid[] = "Your-ssid";
char pass[] = "Your-password";
void setup() {
Serial.begin(9600);
delay(500);
Serial.print("Connecting to ");
Serial.println(ssid);
delay(500);
WiFi.disconnect();
WiFi.begin(ssid,pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.println(".");
}
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.println ("Successfully connected! ");
Serial.print("IP Address allotted to NodeMCU ESP: ");
Serial.println (WiFi.localIP());
Serial.print("MAC Address of ESP: ");
Serial.println (WiFi.macAddress());
WiFi.printDiag(Serial);
}
// the loop function runs over and over again forever
void loop() {
}
Fig.4. Code to connect to wifi network with ESP8266 and print the network details to which the device is connected.

After uploading, hit the reset button on the MCU, or reconnect the USB with the serial monitor open in Arduino IDE.