Through this tutorial, you will learn why we prefer NodeMcu other than Development boards, such as Arduino and Raspberry Pi, which are common choices when prototyping new IoT devices. Those development boards are essentially mini-computers that can connect to and be programmed by a standard PC or Mac. After it has been programmed, the development boards can then connect to and control sensors in the field; by reading this tutorial, you will learn why we prefer Nodemcu.
Because the “I” in IoT stands for the internet, the development boards need a way to connect to the internet. In the field, the best way to connect to the internet is by using wireless networks. However, Arduino and Raspberry Pi do not have built-in support for wireless networks. Developers will have to add a wifi or cellular module to the board and write code to access the wireless module.
In this Tutorial, I will introduce an open-source IoT development board called NodeMCU. One of its most unique features is that it has built-in support for wifi connectivity, hence making IoT application development much easier.
Definition:
The NodeMCU (Node MicroController Unit) is an open-source software and hardware development environment built around a very inexpensive System-on-a-Chip (SoC) called the ESP8266.
Simply, NodeMCU is an open source LUA based firmware developed for ESP8266 wifi chip. Here what is open source means NodeMCU hardware design is open for edit/modify/build.
Anyone can edit/modify/produce it and market their modified NodeMCU Development boards. Generally, we can see NodeMCU Dev boards of Amica, Doit, Lolin & D1 mini /Wemos etc., in the market.
Here What is Lua:
Lua is a powerful and fast programming language designed to be a lightweight, embeddable scripting language.
What is firmware:
Firmware is programming that’s written to a hardware device’s nonvolatile memory. Nonvolatile memory is a static random access memory whose contents are saved when a hardware device is turned off or loses its external power source.
By exploring functionality with the ESP8266 chip, NodeMCU firmware comes with an ESP8266 Development board/kit, i.e. NodeMCU Development board.
There are two nodemcu versions nodemcu v0.9(version1),
Now we will talk about nodemcu version 2, which usually comes in black-coloured PCB.
NodeMCU Dev Kit/board consists of ESP8266 wifi-enabled chip.
The ESP8266 is a low-cost Wi-Fi chip developed by Espressif Systems.
What is this Esp8266 chip?
ESP8266 is Wi-Fi enabled system-on-chip (SoC) module developed by the Espressif system. It is mostly used to create embedded, IoT (Internet of Things) applications.
In Esp8266 is the Esp-12E model , it is embedded with Tensilica L106 32-bit micro controller (MCU)
ESP8266 comes with the capabilities of:
- 2.4 GHz Wi-Fi (802.11 b/g/n, supporting WPA/WPA2),
- general-purpose input/output (16 GPIO),
- Inter-Integrated Circuit (I²C) serial communication protocol,
- analog-to-digital conversion (10-bit ADC)
- Serial Peripheral Interface (SPI) serial communication protocol,
- I²S (Inter-IC Sound) interfaces with DMA(Direct Memory Access) (sharing pins with GPIO),
- UART (on dedicated pins, plus a transmit-only UART can be enabled on GPIO2), and
- Pulse-width modulation (PWM).
In future, I will make Tutorials in which GPIO Pins are fixed for all these communication protocols.
- The CPU clock speed is 80MHz. It can also reach a maximum value of 160MHz.
Static Random access memory and ROM
ESP8266EX WiFi SoC is embedded with a memory controller, including SRAM and ROM. - RAM size < 36kB, that is to say, when ESP8266EX is working under the station mode and is connected to the router, programmable space accessible to the user in the heap and data section is around 36kB.
- There is no programmable ROM in the SoC. Therefore, the user program must be stored in an external SPI flash.
External SPI Flash:
This module is mounted with a 4 MB external SPI flash to store user programs. If larger definable storage space is required, an SPI flash with a larger memory size is preferred. Theoretically speaking, up to 16 MB of memory capacity can be supported.
NodeMCU Dev Kit has Arduino-like Analog (i.e. A0), and Digital (D0-D8) pins on its board.
Using such serial protocols, we can connect it with serial communication devices like I2C-enabled LCD, HMC, MPU-6050 Gyro meter + Accelerometer, RTC chips, GPS modules, touch screen displays etc.
SINGLE-CHIP USB TO UART Interface BRIDGE:( Asynchronous Serial Data BUS (UART))
Integrated USB transceiver; no external resistors required
Integrated clock; no external crystal required
On-chip power-on reset circuit
On-chip voltage regulator: 3.3 V output
This UART Supports Baud rates: 300 bps to 1 Mbits
Now we know that the NodeMCU Development board is featured with wifi capability, analog pins, digital pins and serial communication protocols.
To start using NodeMCU for IoT applications, we first need to know how to write/download NodeMCU firmware in NodeMCU Development Boards. And before that, where we will get the NodeMCU firmware which we need?
There is an online NodeMCU custom build available, using which we can easily get our custom NodeMCU firmware according to our requirements.
In the next tutorial, I will tell you about this firmware download.
How to write codes for NodeMCU?
After setting up ESP8266 with Node-MCU firmware, let’s see the IDE (Integrated Development Environment) required for the development of NodeMCU.
NodeMCU with ESPlorer IDE
Lua scripts are generally used to code the NodeMCU. Lua is an open-source, lightweight, embeddable scripting language built on top of C programming language.
NodeMCU with Arduino IDE
Here is another way of developing NodeMCU with a well-known IDE, i.e. Arduino IDE. We can also develop applications on NodeMCU using an Arduino development environment. This makes easy for Arduino developers to learn Arduino constructs than learning a new language and IDE for NodeMCU.
Difference in using ESPlorer and Arduino IDE
We can say there is a programming language difference while developing an application for NodeMCU using ESPlorer IDE and Arduino IDE.
We need to code in C\C++ programming language if we are using Arduino IDE for developing NodeMCU applications and Lua language using ESPlorer IDE.
NodeMCU is Lua Interpreter so that it can understand Lua script easily. When we write Lua scripts for NodeMCU and send/upload them to NodeMCU, they will be executed sequentially. It will not build a binary firmware file of code for NodeMCU to write. It will send the Lua script as it is to NodeMCU to get executed.
In Arduino IDE, when we write and compile code, the ESP8266 toolchain in the background creates a binary firmware file of the code we wrote. And when we upload it to NodeMCU, it will flash all NodeMCU firmware with newly generated binary firmware code. It writes the complete firmware.
That’s why NodeMCU does not accept other Lua scripts/code after Arduino IDE flashes it. After getting flashed by Arduino sketch/code, it will be no more Lua interpreter, and we get an error if we try to upload Lua scripts. To again start with the Lua script, we need to flash it with NodeMCU firmware.
Since Arduino IDE compiles and uploads/writes complete firmware, it takes more time than ESPlorer IDE.
For more information watch: