Setup Arduino Environment for NodeMCU Programming

In the previous tutorial, we have discussed the basics of ESP8266 modules and have also had a look at the different WiFi modules based on ESP8266. In today's tutorial, we are going to set up Arduino Environment for NodeMCU Programming. Today we will prepare the development environment and build code to blink an LED and report status on the Serial Port (to validate the configuration). We will use the Arduino IDE for coding and the NodeMCU board (a module that works with an ESP8266). Simple integration. Zero hardware complexity.

The ESP8266 is an extremely robust and versatile microcontroller, which has proven to be a powerful tool in building Internet of Things solutions. What makes the ESP8266 such a popular tool is the perfect integration between a robust 32-bit processor and a fully functional WIFI module that already includes Internet Protocols.

A simple target, but the goal here is to prepare and test the development environment and introduce the programming mode.

Material

  • 1x Computer/notebook with the minimum requirements to install Arduino IDE;
  • 1x Mini-USB cable;
  • 1x NodeMCU

Arduino IDE Install

  •  Our first step is to download the Arduino IDE installer. It is available at this URL (https://www.arduino.cc/en/software).
  • Figure 2 shows the latest stable version 1.8.15.
  • It is recommended that you always have the most current version.
  • So, if there’s a newer version when you download it, it’s the right for you. The Arduino community provides constant improvements to the IDE.
  • On the right side, you can find the correct version for each Operating System and download the correct installer.
  • We will not go into details here about how to install from the file. The Arduino page itself features an excellent manual on Getting Started.
  • If this is your first contact with Arduino, I recommend checking out the Learn Arduino section as well.

Arduino IDE Presentation

  • So, IDE installed, let's get to know the interface before making some important settings.
  • If everything is ok, you should get the following result when running Arduino.
 

Text Editor

  • The first thing that should catch your attention is that the code has already started with two functions.
  • The “void setup()” and the “void loop()”.
  • Arduino maintains a bootloader in the microcontroller, which is an initiator program responsible for preparing the hardware for correct operation.
  • When we turn the module on power or press the reset button, the bootloader is the first program to run.
One of the bootloader's main responsibilities is to receive the code we send and write it to the microcontroller's memory. And when the code plays, the bootloader asks two questions:

1– What do I do first?

Answer: What does the “setup()” function say to do.

2– What do I do after “setup()”?

Answer: Repeatedly execute whatever the “loop()” function tells you to do.

  • By default, we use the “setup()” function to inform whether a pin will operate as input or output, set the initial state of each pin used, set serial port Baud Rate, initialize additional configuration functions.

Verify and Upload Buttons

  • Once our code is done, we need to check if everything is right and write the code in the microcontroller.
  • The check button does a code check to identify syntax or library integration errors. Attention: logic errors are not checked; these are up to the programmer.
  • The Upload button also performs the verification and then sends the code to the microcontroller via the Serial port.

Feedback Interface

  • Perhaps the most important snippet of the IDE, here it reports the status of testing and recording. This is where you see if everything is ok.

Serial Monitor

  • The Arduino IDE has a tool called Serial Monitor that allows direct communication with the microcontroller from the Serial port.
  • It is possible to follow what is being sent by the module and send commands directly to it.

Two points of attention

  1. The Communication Port (in the example COM3) must be selected in the Tools
  2. The Baud Rate (in this case, 115200) must be entered correctly, otherwise, the data may become illegible or simply not appear.
  3. Baud Rate can be set in the “setup()” function when preparing the recording

Boards Manager

  • Each Arduino module has its peculiarities. Amount of memory, available pins, etc.
  • Just as important as making a well-built code is telling the IDE which card model will be used.
  • IDE Arduino already brings in its basic installation, the installation of boards that use ATMEGA microcontrollers.
  • If you are going to use another type of board, it needs to be installed in Boards Manager (tools -> Boards Manager...).
  •  Once installed, the board will be available and must be selected from the Tools -> Board menu.

Attention point

  • Until Arduino version 1.8.15, modules using the ESP8266 do not appear available in Boards Manager.
  • This is because it is not yet included in the official Arduino repository.
  • For it to appear, it is necessary to add the path of a new repository.
  • Do this by going to the File -> preferences menu and add http://arduino.esp8266.com/stable/package_esp8266com_index.json in the Additional Boards Manager URLs field.
  • Press OK, close Arduino, and open it again.
  • In Boards Manager the ESP8266 option will be available. Click install.

Once this step is completed, the main modules using the ESP8266 will be available. For our application, we will use nodeMCU 1.0.

Coding NodeMCU with Arduino IDE

  • After choosing the board, choosing the port (note, the port will only appear when you connect the board to the USB), it's time to make our first code.
  • The nodeMCU Module has a built-in LED and we will make it blink every 1 second.
  • For this sketch, we don't need to include any additional libraries.
  • When we inform Arduino that we are using the NodeMCU board, it already knows who the LED_BUILTIN is and which pin it is connected to.
  • We use #define LED LED_BUILTIN just to give a more practical name to our LED, it could be used to name an external pin, for example, #define LED 13, alternatively, the original name could be used in the code.
  • pinMode(LED, OUTPUT) and pinMode(13, OUTPUT) would have the same effect.
  • The pinMode(LED, OUTPUT), by the way, is used to inform that this pin will operate as output. Note that this configuration was done inside the setup() function, so the pin will be prepared before being used in another function.
  • Serial.begin(115200) initializes communication with the serial port at baud rate 115200. In our Loop function we will follow the sequence:
  • Turn off the LED, write the pin status to the serial, wait for 1 second, turn the LED on, write the pin reading to the serial, wait for 1 second and start all over again.
  • Here's the video demonstration of LED Blinking with NodeMCU:
So, that was all for today. I hope you guys have enjoyed today's tutorial on LED Blinking with NodeMCU. In the next tutorial, we will have a look at How to connect NodeMCU with webserver. Stay Tunned. Thanks !!! :)

Introduction to NodeMCU V3

Hi Friends! Welcome you onboard. I am back to give you a daily dose of useful information. Today, I'll unlock the detailed Introduction to NodeMCU V3. It is an open-source firmware and development kit that plays a vital role in designing your own IoT product using a few Lua script lines. The module is mainly based on ESP8266 that is a low-cost Wi-Fi microchip incorporating both a full TCP/IP stack and microcontroller capability. It is introduced by manufacturer Espressif Systems - A manufacturer based in Shanghai, China. Arduino Modules and Microcontrollers have always been a great choice to incorporate automation into the relevant project. But these modules come with a little drawback as they don't feature a built-in WiFi capability, subsequently, we need to add external WiFi protocol into these devices to make them compatible with the internet channel. This is where NodeMCU V3 comes handy that incorporates a built-in WiFi support, giving an easy pathway to design IoT applications as per your technical requirements. In this post, I'll try to cover brief details related to this WiFi Development Kit, its main features, pinout and everything you need to know about this module. Let's get started.

Introduction to NodeMCU V3

NodeMCU V3 is an open-source firmware and development kit that plays a vital role in designing your own IoT product using a few Lua script lines. Multiple GPIO pins on the board allow you to connect the board with other peripherals and are capable of generating PWM, I2C, SPI, and UART serial communications.
  • The interface of the module is mainly divided into two parts including both Firmware and Hardware where former runs on the ESP8266 Wi-Fi SoC and later is based on the ESP-12 module.
The firmware is based on Lua - A scripting language that is easy to learn, giving a simple programming environment layered with a fast scripting language that connects you with a well-known developer community. And open source firmware gives you the flexibility to edit, modify and rebuilt the existing module and keep changing the entire interface until you succeed in optimizing the module as per your requirements.
  • USB to UART converter is added on the module that helps in converting USB data to UART data which mainly understands the language of serial communication.
Instead of the regular USB port, MicroUSB port is included in the module that connects it with the computer for dual purposes: programming and powering up the board.
  • The board incorporates status LED that blinks and turns off immediately, giving you the current status of the module if it is running properly when connected with the computer.
The ability of module to establish a flawless WiFi connection between two channels makes it an ideal choice for incorporating it with other embedded devices like Raspberry Pi.

NodeMCU V3 Pinout

NodeMCU V3 comes with a number of GPIO Pins. Following figure shows the Pinout of the board.
  • There is a candid difference between Vin and VU where former is the regulated voltage that may stand somewhere between 7 to 12 V while later is the power voltage for USB that must be kept around 5 V.

NodeMCU V3 Datasheet

  • You can download NodeMCU V3 datasheet by clicking the below button:
Download NodeMCU V3 Datasheet

NodeMCU V3 Features

  • Open-source
  • Arduino-like hardware
  • Status LED
  • MicroUSB port
  • Reset/Flash buttons
  • Interactive and Programmable
  • Low cost
  • ESP8266 with inbuilt wifi
  • USB to UART converter
  • GPIO pins
As mentioned above, a cable supporting micro USB port is used to connect the board. As you connect the board with a computer, LED will flash. You may need some drivers to be installed on your computer if it fails to detect the NodeMCU board. You can download the driver from this page. Note: We use Arduino IDE software for programming this module. It is important to note that the pin configuration appearing on the board is different from the configuration we use to program the board on the software i.e. when we write code for targeting pin 16 on the Arduino IDE, it will actually help is laying out the communication with the D0 pin on the module. Following figure the shows the pin configuration to use in Arduino IDE.

How to Power NodeMCU V3?

You can see from the pinout image above, there are five ground pins and three 3V3 pins on the board. The board can be powered up using the following three ways. USB Power. It proves to an ideal choice for loading programs unless the project you aim to design requires separate interface i.e. disconnected from the computer. Provide 3.3V. This is another great option to power up the module. If you have your own off-board regulator, you can generate an instant power source for your development kit. Power Vin. This is a voltage regulator that comes with the ability to support up to 800 mA. It can handle somewhere between 7 to 12 V. You cannot power the devices operating at 3.3 V, as this regulator unable to generate as low as 3.3V.

NodeMCU V3 Projects and Applications

NodeMCU V3 is mainly used in the WiFi Applications which most of the other embedded modules fail to process unless incorporated with some external WiFi protocol. Following are some major applications used for NodeMCU V3.
  • Internet Smoked Alarm
  • VR Tracker
  • Octopod
  • Serial Port Monitor
  • ESP Lamp
  • Incubator Controller
  • IoT home automation
  • Security Alarms
That's all for now. I hope I have given you something valuable related to this module. If you have any question, you can approach me in the comment section below. I'd love to help you the best way I can. You are most welcome to keep us updated with your valuable feedback so we keep producing quality content as per your needs and requirements. Thanks for reading the article.
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir