Getting Started with ESP8266 NodeMCU Programming Using Arduino IDE.

ESP8266 NodeMCU programming using Arduino IDE

NodeMCU is an open source IoT platform that includes Lua based firmware running on the ESP8266 WiFi SoC from Espressif Systems, and hardware based on the ESP-12 module. ESP8266 NodeMCU boards are ideal for IoT and other wireless connection applications.

In this tutorial I will give an introduction to ESP8266 NodeMCU development boards including the hardware and pinout structure and how to begin programming these boards with Arduino IDE.

Hardware Overview of the ESP8266 NodeMCU.

The ESP8266 NodeMCU boards come in different versions. The first version was NodeMCUV0.9 by Amica which was based on ESP-12. However, this board is no longer manufactured mainly because its width was not breadboard friendly.

NodeMCUV1.0 also by Amica is the second generation of NodeMCU and is the most popular one. This board upgraded from ESP-12 to ESP-12E giving it extra pins and is also narrower and fits on a breadboard.

NodeMCU V3 version was invented by Lolin and has the same pinout structure as V1.0 but uses a CH340G USB to TTL converter chip instead of the Silabs CP2102 from V1.0. Also, this board is slightly larger than the V1.0

ESP8266 NodeMCU hardware overview

ESP8266 NodeMCU boards have Tensilica Xtensa 32-bit LX106 RISC processor. This microprocessor supports Real Time Operating System (RTOS) and operates at 80MHz to 160 MHz adjustable clock frequency. There is 128 KB RAM and 4MB of Flash memory to store data and programs with in-built Wi-Fi / Bluetooth and Deep Sleep Operating features.

ESP8266 NodeMCU module pinout.

The diagram below shows the pinout of the ESP8266 NodeMCU board.

ESP8266 NodeMCU pinout

Power Pins These include VIN pin and three 3.3V pins.

  • VIN pin can be used to directly supply power to the NodeMCU board and its peripherals, if you have a regulated 5V voltage source. The board can also be powered through the micro-USB port.
  • The 3.3V pins are the output of an on-board voltage regulator. These pins can be used to supply power to external components.

GND is a ground pin of ESP8266 NodeMCU development board.

I2C Pins – There is only one I2C which is realized via software programming with a maximum clock frequency of 100kHz. It used to connect with other microcontrollers and other components like sensors. Both I2C Master and I2C Slave are supported. It should be noted that I2C clock frequency should be higher than the slowest clock frequency of the slave device.

GPIO Pins – There are 17 GPIO pins which can be assigned to various functions by programming the appropriate registers. These pins can be multiplexed with other functions such as I2C, I2S, UART, PWM, and IR Remote Control.

ADC – ESP8266 NodeMCU is embedded with a 10-bit precision SAR ADC at pin6 (TOUT). This ADC can perform the functions below but they cannot be implemented at the same time;

  • Measuring the power supply voltage of VDD3P3 (Pin3 and Pin4)
  • Measuring the input voltage of TOUT (pin6).

UART Pins – ESP8266 NodeMCU has two UART interfaces, that is, UART0 and UART1. Data transmission speed via UART interfaces can go up to 4.5 Mbps.

SPI Pins – There are two SPIs (SPI and HSPI) in slave and master modes. SPI mode can be implemented via software programming with maximum clock frequency of 80 MHz when working as a master and 20 MHz when working as a slave.

SDIO Pins – This is the Secure Digital Input/Output Interface (SDIO) used for interfacing SD cards. It supports 25 MHz SDIO v1.1 and 50 MHz SDIO v2.0, and 1 bit/4-bit SD mode and SPI mode.

PWM Pins – The board has four of Pulse Width Modulation (PWM) output interfaces whose functionality can be implemented via software programming. The PWM frequency range is between 100Hz to 1kHz and can be used for driving digital motors and LEDs.

Control Pins are used to control ESP8266. These pins include Chip Enable pin (EN), Reset pin (RST) and WAKE pin.

IR Remote Control – ESP8266 currently supports one infrared remote control interface using GPIO14 and GPIO5 for IR TX and IR Rx respectively.  This functionality can be implemented via software programming and supports NEC coding, modulation and demodulation. The frequency of modulated carrier signal is 38 kHz, while the duty ratio of the square wave is 1/3.

More details regarding pinout specifications for ESP8266 NodeMCU pinout can be got form the ESP8266 datasheet from Expressif Systems.

Preparing Arduino IDE for programming ESP8266 NodeMCU.

Before you can program ESP8266 NodeMCU using Arduino IDE, you need to configure the Arduino IDE with the necessary packages to handle the corresponding hardware by following the steps below.

Installing the NodeMCU package for Arduino IDE.

First open the Arduino IDE and go to Files and click on the Preference. You should get a dialogue box as shown below.

Paste the URL below in the Additional boards Manager

http://arduino.esp8266.com/stable/package_esp8266com_index.json
Installing ESP8266 package in Arduino IDE

Installing the ESP8266 Boards manager package.

Next go Tools > Board > Boards Manager to access the Boards Manager and there you search for ‘esp8266 by ESP66 Community’ and click Install.

Installing ESP8266 boards manager in Arduino IDE

Specifying the type of NodeMCU board being used.

Plug your ESP8266 NodeMCU into your computer using micro-B USB cable.

In the Arduino IDE go to Tools>Board>ESP866 Boards and select the type of NodeMCU that you are using for example in my case it is NodeMCU 1.0(ESP-12E Module).

Selecting the type of NodeMCU being used

Now plug your NodeMCU board into your computer.

Under Tools make sure you select the correct COM port being used by the NodeMCU module and the Upload Speed of 115200 otherwise you may get errors when uploading code sketches if these settings are not properly configured.

Checking NodeMCU upload speed and COM port

Drivers for CP2102 or CH340G USB to TTL Converter.

One of the challenges you may encounter with NodeMCU boards is the necessary drivers for the USB to TTL converter of the board you are using either not being available or not functioning properly with your computer’s operating system.

Usually, Windows 10 will automatically recognize CP2102 chip and activate the appropriate drivers but CH340G drivers require separate installation. CH340G drivers can be downloaded form the manufacturers website.

Sometimes if the drivers are installed but not functioning properly you need to uninstall the old drivers and install the most recent version.

Testing the ESP8266 NodeMCU by blinking an LED.

If all the above steps have been successfully implemented, then you can go ahead and test your NodeMCU module using the example of a blinking LED.

The LED will be attached to GIOP16 or D0 as shown below.

Connecting LED to ESP8266 NodeMCU schematic

The code simply declares pin16 as an output pin and blinks the LED by turning this pin HIGH and LOW with small time delays like every after 1 second.

void setup()
{
	pinMode(D0, OUTPUT);
}
void loop()
{
	digitalWrite(D0, HIGH);
	delay(1000);
	digitalWrite(D0, LOW);
	delay(1000);
}

Does the NodeMCU V3 board have a built-in LED?

If you are beginning programming ESP8266 NodeMCU V3 board, you may be confused since most documentations point out that NodeMCU boards have an on-board LED on GPIO16 or D0 but if you use this pin for the V3 board to run the blinking LED example above, no on-board LED will blink!

The answer to this is that ESP8266 NodeMCU V3 has only one built-in led attached to GPIO2 or D4. This LED is active low, that is, setting D4 to ‘LOW’ will turn the LED ON and setting it to ‘HIGH’ will turn the LED OFF.

However, ESP8266 NodeMCU V1.0 has two on-board LEDs attached to GPIO16 and GPIO2 and since this board is the most popular, many of the examples provided within the Arduino ESP8266 libraries are based on this module and the blinking LED example will use GPIO16 therefore if you are using NodeMCU V3 you need to change this pin declaration.

With the above introduction, you can now be able to use ESP8266 NodeMCU with the Arduino IDE in a number of applications. I have done various projects using this board which you can refer to using the links below;

You may also like...