In the previous tutorial, the Arduino IDE has been installed. In this tutorial, we will create the first program. This program uses the on-board LED on ESP-12E module. The LED will blink every 1 s. Before we go to the programming, we must install the NodeMCU USB driver. The step-by-step how to install the NodeMCU driver is described as the following:
- Download NodeMCU driver from this link.
- Connect NodeMCU board to the USB port.
- Run the driver installer file: CH341SER.EXE, and install the driver.
The NodeMCU board has one on-board blue LED. Actually, the LED is on ESP-12E module, as shown in the following figure. The LED is connected to GPIO2 of the ESP8266. We will create a program for blinking the LED every 1 s. The example code for blinking the LED is shown in the following listing.
// Set GPIO2 as output
// Turn on the active-low LED
// Turn off the active-low LED
In setup function, we set GPIO2 as output. The GPIO2 is connected to the on-board LED. In loop function, we write logic LOW to turn on the LED, because the LED circuit is active-low. After that, we add 1000 ms delay. To turn off the LED, we write logic HIGH. Finally, we add 1000 ms delay again. To compile the program, we can click the Verify button.
Before we download the program into the ESP8266, we should set board’s COM port in Arduino IDE. You can find the board’s COM port from Device Manager, as shown in the following figure. You can set the COM port from Tools → Port menu. After that, we can download the program by clicking Upload button. After the program is downloaded into the ESP8266, the on-board LED will blink every 1 s.
In this tutorial, you have learned how to create the first program for the ESP8266. In the next tutorial, I will explain more about GPIO output and LED.
Go to the part 3 of the tutorial.