Introduction to NodeMcu

Introduction to NodeMcu:

By this tutorial, you will learn why we prefer NodeMcu other than Development boards, such as Arduino and Raspberry Pi, 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.

arduino-uno
arduino-uno(Buy now)
Raspberri pi
Raspberri pi(buy now)

Because the “I” in IoT stands for 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.

By 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, and hence makes IoT application development much easier.

Nodemcu

Definition:

The NodeMCU (Node MicroController Unit) is an open source software and hardware development environment that is 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.

Its like anyone can edit/modify/produce it and market their modified NodeMCU Development boards. Generally, we can see NodeMCU Dev boards of

Amica

amica nodemcu
amica nodemcu

DOIT

Doit nodemcu
Doit nodemcu

Lolin & D1 mini /Wemos  etc. in market.

Here What is Lua:

Lua is a powerful and fast programming language which is 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 form of 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 ESP8266 chip, NodeMCU firmware comes with ESP8266 Development board/kit i.e. NodeMCU Development board.

There are Two nodemcu versions like nodemcu v0.9(version1)

nodemcu version1
nodemcu version1

Nodemcu v1. 0 (version 2)

Nodemcu version2
Nodemcu version2

Now we will talk about nodemcu veron 2 which usually comes in black colored PCB.

NodeMCU Dev Kit/board consist of ESP8266 wifi enabled chip.
The ESP8266 is a low-cost Wi-Fi chip developed by Espressif Systems

What is this Esp8266 chip?

ESP8266 inner parts
ESP8266 chip

ESP8266 is Wi-Fi enabled system on chip (SoC) module developed by Espressif system. It is mostly used for development of IoT (Internet of Things) embedded applications.
In Esp8266 is the Esp-12E model , it is embedded with Tensilica L106 32-bit micro controller (MCU)

ESP8266 comes with 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, Tutorials  I will make which GPIO Pins fixed for all this 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 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 user in 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 an 4 MB external SPI flash to store user programs. If larger definable storage space is required, a SPI flash with larger memory size is preferred. Theoretically speaking, up to 16 MB 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 devices like I2C enabled LCD display,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))

uart cp2102
uart cp2102

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 came to know that, NodeMCU Development board is featured with wifi capability, analog pin, digital pins and serial communication protocols.

To get start with using NodeMCU for IoT applications first we need to know about how to write/download NodeMCU firmware in NodeMCU Development Boards. And before that where this NodeMCU firmware will get as per our requirement.

There is online NodeMCU custom builds available using which we can easily get our custom NodeMCU firmware as per our requirement.

In next tutotial I will tell u 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 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.

Esplorer IDE
Esplorer IDE

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 Arduino development environment. This makes easy for Arduino developers than learning new language and IDE for NodeMCU.

ide-arduino-arduino
ide-arduino-arduino

Difference in using ESPlorer and Arduino IDE

Well, there is a programming language difference we can say while developing 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 if we are using ESPlorer IDE.
Basically, NodeMCU is Lua Interpreter, so it can understand Lua script easily. When we write Lua scripts for NodeMCU and send/upload it to NodeMCU, then they will get executes sequentially. It will not build binary firmware file of code for NodeMCU to write. It will send Lua script as it is to NodeMCU to get execute.

In Arduino IDE when we write and compile code, ESP8266 toolchain in background creates binary firmware file of code we wrote. And when we upload it to NodeMCU then it will flash all NodeMCU firmware with newly generated binary firmware code. In fact, it writes the complete firmware.

That’s the reason why NodeMCU not accept further Lua scripts/code after it is getting flashed by Arduino IDE. After getting flashed by Arduino sketch/code it will be no more Lua interpreter and we got error if we try to upload Lua scripts. To again start with Lua script, we need to flash it with NodeMCU firmware.
Since Arduino IDE compile and upload/writes complete firmware, it takes more time than ESPlorer IDE.

For more information watch:

Leave a Reply

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

%d bloggers like this: