Light Up an LED: Programming NodeMCU with Arduino IDE

Light Up an LED: Programming NodeMCU with Arduino IDE

Previously, we introduced “ESP8266 and the IoT magic tool NodeMCU”, many friends expressed interest but felt that the author did not mention any practical content. Since this is the case, the author will periodically release some tutorials on this IoT learning tool, NodeMCU.

Light Up an LED: Programming NodeMCU with Arduino IDE

The Origin of NodeMCU

In “ESP8266 and the IoT magic tool NodeMCU”, we talked about how before the ESP8266 appeared, the cost of connecting Arduino to the internet was very high, especially through WiFi. The price of an official Wi-Fi expansion board was enough to buy three official Arduino UNOs.

Light Up an LED: Programming NodeMCU with Arduino IDE

However, since Espressif launched the ESP8266EX chip, open-source hardware enthusiasts discovered its great potential: “Wow, this chip can provide WiFi connectivity to Arduino for less than 10 yuan!” Later, the ESP8266 module became synonymous with the current Arduino WiFi module.

Light Up an LED: Programming NodeMCU with Arduino IDE

Later, people discovered that the ESP8266EX chip contains a 32-bit processing chip, the Tensilica L106, which performs well, and only uses 20% of its performance for handling WiFi, leaving the remaining potential available for development. Thus, some people added peripheral circuits to the ESP8266EX chip to create relatively independent and complete development boards. These minimal systems usually include USB serial communication, power management modules, and rich pin interfaces. Among them, NodeMCU is one of the most stable development boards.

Light Up an LED: Programming NodeMCU with Arduino IDE

Hardware Versions of NodeMCU

There are two hardware versions of NodeMCU on the market — LoLin and Amica. Compared to Amica, LoLin is slightly larger and uses the CH340 serial chip instead of the CP2102. But other than that, there is no significant difference. The Lolin using CH340 requires specific drivers to be installed before use, while CP2102 generally supports plug-and-play, with Windows/Mac systems automatically recognizing and downloading drivers.

Light Up an LED: Programming NodeMCU with Arduino IDE

ESP8266 Core for Arduino

The native programming language of NodeMCU is not assembly nor Arduino’s C++, but a scripting language called Lua. It can be said that the number of users is relatively niche, but since the appearance of the ESP8266 core for Arduino library, it has quickly made ESP8266/NodeMCU popular in the Arduino community. What is ESP8266 core for Arduino? In short, with it, you can program NodeMCU using the Arduino way (IDE programming environment, Arduino language, libraries). It can be said that NodeMCU is an Arduino with built-in WiFi functionality! It has complete pins and is compact.

Light Up an LED: Programming NodeMCU with Arduino IDE

Practice: Light Up an LED

After introducing the background, let’s practice the classic LED lighting experiment.

1. Install the Driver

First, determine whether you need to install the serial driver based on your version of NodeMCU (Amica or Lolin). The larger Lolin definitely requires the installation of the CH340 driver. You can download the corresponding driver program for your system from the following website:

http://www.wch.cn/download/CH341SER_EXE.html

If the installation is successful, after connecting NodeMCU to the computer via USB, you can see a serial port with the CH340 label in the device manager’s port section.

Light Up an LED: Programming NodeMCU with Arduino IDE

For Mac users, you can also check the serial port by entering the following command in the command line tool:

ls /dev/tty*

If you see something like “tty.wchusbserialxxxx”, it indicates that the driver has been installed successfully.

Light Up an LED: Programming NodeMCU with Arduino IDE

If you have the Amica version of NodeMCU, normally, when you plug it into USB, the system will automatically recognize it without needing to install a driver. However, in some cases, it may fail to auto-recognize. You can also check in the device manager’s port section if there is a CP201x label.

Light Up an LED: Programming NodeMCU with Arduino IDE

Mac users should check for the presence of “tty.SLAB_USBtoUART”. If not, go to the following website to select and install the driver program for your corresponding system:

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

If after installation it is still not recognized, then the board you bought may be defective.

2. Install ESP8266 Core for Arduino

The second step is that the ESP8266 core for Arduino is not a library that comes with the Arduino IDE; we need to install it manually. Open the Arduino IDE from the menu > File > Preferences.

In the Additional Board Manager URLs field, fill in: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Light Up an LED: Programming NodeMCU with Arduino IDE

Restart the IDE, open Tools -> Board -> Board Manager

Wait a moment, then scroll down to the bottom and install esp8266 by ESP8266 Community

Light Up an LED: Programming NodeMCU with Arduino IDE

After successful installation, restart the IDE, and in the Tools > Board menu, you will find the boards supported by Arduino Core For ESP8266, including NodeMCU.

Light Up an LED: Programming NodeMCU with Arduino IDE

Note: Many people encounter the error “File download failed” during the installation process.

Light Up an LED: Programming NodeMCU with Arduino IDE

It is highly likely that your network cannot access the resource website. One way is to use a VPN to try again, or refer to the following website for methods to download all installation files offline:

http://file.yfrobot.com/file/wifi/nodemcu/arduino/arduinoIDEForTheESP8266.html

3. Choose the Correct Board

Tools > Board > Select the preset NodeMCU 1.0

Ensure that NodeMCU is connected to the USB port of the computer, then select the correct serial port in Tools > Port.

Light Up an LED: Programming NodeMCU with Arduino IDE

4. Connect the Circuit

Connect the circuit board as shown in the diagram.

Light Up an LED: Programming NodeMCU with Arduino IDE

The LED_BUILTIN of NodeMCU is GPIO16/D0

Light Up an LED: Programming NodeMCU with Arduino IDE

Upload Code

As mentioned earlier, as long as you have installed the ESP8266 core for Arduino, most existing code examples and libraries of Arduino can be used directly. We open the Blink example code.

// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin LED_BUILTIN as an output.

pinMode(LED_BUILTIN, OUTPUT);

}

// the loop function runs over and over again forever

void loop() {

digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

Like regular Arduino operations, just click upload. Of course, the code compilation and upload process for NodeMCU takes a bit longer than for regular Arduino.

If successful, we will see the LED blinking.

Light Up an LED: Programming NodeMCU with Arduino IDE

Isn’t it simple? Of course, the true power of NodeMCU does not stop here; see you in the next tutorial. If you’re interested in buying a NodeMCU to try:

https://item.taobao.com/item.htm?id=580998229338

Want to get the Arduino e-book and video tutorials included with our kit?

Scan the QR code below to follow us, then reply with “Benefits

Light Up an LED: Programming NodeMCU with Arduino IDE

Light Up an LED: Programming NodeMCU with Arduino IDE

Click to read the original text and purchase the Arduino beginner learning kit

Leave a Comment

Your email address will not be published. Required fields are marked *