Programming NODEMCU with Arduino IDE
- Present the ESP8266 integrated in the NodeMCU module.
- Download the ESP8266 plugin for the Arduino IDE.
- Configure the environment
- Our first program with NodeMCU, blinking LED..
Bill of materials
NodeMCU: a microcontroller based on the ESP8266
We have already talked about the WIFI module ESP8266 on other occasions, but today we are going to talk about a board that is based on it: the NodeMCU v1.0. We want to emphasize that if you want to play with it it is convenient that you look for version 1.0 because the changes introduced have been huge and for the better.
One of those changes is that the processor that includes, in the 12E version, or Enhanced: we have 6 more pins, four of which are dedicated to the SPI communication, which are the CS0, MISO, MOSI and SCLK .
You can see the new pins in the following scheme:
In the ESP2866 Models tutorial we already introduced the NodeMCU and we said that if it was confirmed that it could be programmed as an Arduino using the ESP8266 plugin it could be the Arduino that we have been waiting for a long time with WIFI included for a ridiculous price.
Well, it is already confirmed and thanks to the group of benefactors of humanity that developed the ESP2866 plugin for the Arduino IDE, we can use it now also to program the NodeMCU from the Arduino IDE.
Instead of having to learn to program the happy module in LUA, we can save time and headaches and start messing directly with it using the C ++ we use in our Arduino IDE.
Let’s remember a bit the advantages offered by the ESP2866 plugin to program the NodeMCU:
- ONE – You can develop with the same IDE that you already know
- TWO – They have made a Cross compiler, so that you practically use the same commands that you use with Arduino, which saves you from learning anything new (And the headaches)
- THREE – Depending on the model of ESP8266 that you have, you have more or fewer pins available with PWM and other things like I2C and SPI, but for the typical model ESP8266-01 (That is the one with almost total probability) you only have two pins available GPIO0 and GPIO2, but we’ll talk about other models with all available pins
- FOUR – That is, you can program the processor of your ESP8266 exactly as if it were an Arduino with the same commands, and in what refers to the WIFI, you can forget the AT commands, because it includes a series of libraries, which mimic the Arduino WIFI library with which you can transplant many programs.
We said that NodeMcu is an Open Source initiative of Espressif systems for the development of a simple model to integrate the IOT wherever it is needed. For this, they develop hardware and software models that facilitate the development of programs and applications based on WIFI.
An advantage over other modules that make up the ESP2866 is that all its pins are available outdoors, in a mount that can be placed on a breadboard (yes, finally) and also includes a mini USB connector to program the internal chip and communicate with the PC if necessary, so we avoid the FTDI to USB adapter that is always cumbersome.
Let’s take a look at the different models of the NodeMCU boards, because being an open-source project there are a number of variants since anyone can produce and sell NodeMCU boards.
Mainly there are three manufacturers: Amica, Doit/Smartduino and Lolin/WeMos. In our case we have tested the Amica NodeMCU version.
First Generation, V1 (version V0.9)
The first generation of NodeMCU plates, which has the v0.9 numbering, has the peculiarity that the color of the plate is usually yellow and that the format is wider than that of its successors, 47 mm x 31 mm. The drawback of this type of plates is that, due to its size, it covers the ten pins of a normal protoboard making it cumbersome to use it for our projects because it does not leave pins free.
Second Generation, V2 (versión V1.0)
In the second generation of plates have already solved the problem of size and we can use the new NodeMCU v1.0 in our protoboards without discomfort, since it leaves us a row of pins available on each side. They also carry the new ESP12E improved chips.
Third Generation, V3 (versión V1.0)
In this case it is not an authentic new version since NodeMCU has not released any new specification, but a version that LoLin has taken out of the sleeve and that presents a series of minor innovations with respect to version V1.0.
In theory, the USB port is more robust and LoLin has used one of the pins reserved for USB output power and one of the reserved pins for an additional GND connection.
Another peculiarity of this version is that the size is larger than that of the Amica and Doit plates. In the following images you can see the difference in size between versions V2 and V3.
Both models are equivalent in terms of performance, but the smaller size of the Amica version can be an advantage.
Well, let’s stop chatting and we’ll mess with our NodeMCU now. But first we have to install it in our PC and for this it is convenient that you follow the steps that we described in this session, in case you do not have it installed yet.
Arduino, if you now select the plates with \Tools\Board, you will see that you can already select the ones corresponding to NodeMCU 1.0 (ESP-12E Module).
We need to select the port on which NodeMCU is installed on our computer, so we navigate to \Tools\Port and select the one that our operating system has chosen for it. In our case we chose the COM7 port.
We already have the NodeMCU installed in the computer, we have downloaded the ESP8266 plugin for the Arduino IDE, we have selected the card and the port in which we have installed it, so we only have check that it works correctly.
TESTING THE BLINKING LED
You already know that the first program that we use with a micro controller is the blinking LED, replacing the famous “Hello World” of the usual programming. It is true that we are going to be very short and wanting to sink more tooth to the NodeMCU, but something has to start and tradition is tradition.
We are going to load the example program of the blinking LED of the ESP8266, that will work to us without no problem in our NodeMCU. For this we will go to \ File\ Examples\ ESP8266\ Blink and we will click on the example.
- Attention: Make sure to load the example that corresponds to the ESP8266, because the LED is on a pin different from the usual 13 of Arduino, and if you do not do so you will not see the flicker.
As always we will load the program on our plate by clicking on the horizontal arrow and we will see that the blue LED of the ESP8266 board, which is in the area of the antenna, begins to flash indicating that the data transfer is being carried out.
Notice that the download of the program is indicated by a line of half ellipses that advances the dump
After a few seconds the transfer will be completed and we will see that the LED on the NodeMCU board starts to flash.
Si todo ha ido bien y vemos cómo parpadea el LED significará que tenemos instalado y configurado nuestro NodeMCU para que en futuras sesiones podamos emprender proyectos de mayor envergadura.
- We have seen the ESP8266 from a new point of view, integrated in the Amica NodeMCU board.
- We have presented the basic configuration of the environment to directly program the NodeMCU.
- We overturned our first program and tested the simple Blinking LED.