The easy way to use the ESP8266 is with the Arduino IDE and this
ESP8266 Arduino tutorial shows you how to install drivers into the
Arduino IDE to program the ESP8266. It then shows you an example sketch
using wifi.
The Lolin nodeMCU V3 breakout
board is an ESP-12E style ESP8266 breakout board which makes it very
easy to use an ESP8266 device - you just plug it into a micro USB
connector and its ready.
Lolin nodeMCU V3 Board
The board includes its own 3V3 power supply regulator, a reset button, a Flash button and a
USB-to-serial chip (CH340G on mine). You can just plug it into a USB
port (micro USB connector) and start using it.
When you follow the instructions
below, you can program the Lolin NodeMCU as if it were any other Arduino
device. This is convenient since it uses the same familiar Arduino IDE
programming environment.
When you power up the nodeMCU for the first time you will see this message - when you connect a serial terminal on the PC - such as Tera Term - at 9600, 8 bits, 1 stop bit, no parity (8 1 N):
This is a LUA interface which is an interactive script system - you can
type
commands directly at the prompt to get the ESP8266 to perform. However
the rest of this page shows you how to use the Arduino programming
environment to program the board in C/C++ as you would with any other
Arduino board.
If you continue past this point and Flash the Arduino sketch then
the LUA environment will be overwritten. If you want to use LUA again
you will need to re-flash the firmware.
The first step in setting up the ESP8266 Arduino IDE is to plug in
the NODEMCU and check the Windows device Manager for an entry in the
Ports section.
If you don't see the NodeMCU showing up as shown below then you will
need to install drivers. The other possibility is that the NodeMCU is
using too much power - I found it would not work from a powered hub but
only from direct connection to the PC USB port. It needs 400mA!
Note: You can add an external power source to the Vin connection on
the board with voltage >5V. Also connect ground labelled 'G' to complete the circuit.
To setup the board use the board manager:
Add the following text to the "Additional Boards Manager URLs":
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Start the Boards manager dialogue. Click Boards Manager...
Search for and install the "esp8266 by ESP8266 community" Entry.
Now select the nodeMCU 1.0 (ESP-12E Module) entry - this is the base
type for nodeMCU. nodeMCU is actually the firmware running on an ESP8266
ESP-12E.
Now check that you have similar information to the following - especially these:
Use the ESP8266 Arduino IDE to load the following sketch - just
copy to white area of the IED and hit the upload button. This shows you a
quick example of the ESP8266 Arudino wifi capability.
This example is from github.
#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);
}
Here's the typical output from the sketch using the serial monitor.
Setup done scan start scan done 15 networks found 1: SKY6F103 (-91)* 2: SKY7C621 (-88)* 3: SKY6F103 (-91)* 4: BTWifi-X (-87) 5: BTHub6-2MX3 (-87)* 6: talktalkt8974 (-61)* 7: VM989231-2G (-82)* 8: BNIPOF_6723 (-16)* 9: VM7227168 (-93)* 10: VM0345159 (-92)* 11: BTWifi-with-FON (-88) 12: Virgin Media (-90)* 13: Virgin Media (-93)* 14: VM-guest3451593 (-89)* 15: Virgin Media (-89)*
End of ESP8266 Arduino IDE tutorial showing how to flash an esp8266
with the Arduino IDE making it easy to create C/C++ based programs
programmed into the ESP8266.
Comments
Have your say about what you just read! Leave me a comment in the box below.
Don’t see the comments box? Log in to your Facebook account, give Facebook consent, then return to this page and refresh it.