Advertisement
nmcu-p6

The NodeMCU (IoT) Guide

nodemcu-p1

The NodeMCU development board is a powerful solution to program microcontrollers and be part of the Internet of Things (IoT). The NodeMCU development board, based on ESP8266EX, is a cute module with a microcontroller, integrated Wi-Fi receiver, and transmitter. NodeMCU supports several programing languages; hence, it is very easy to upload programs from any computer over a micro-USB port. I have been playing with the NodeMCU for quite a while now and, I have to say, it is a lot more fun than the other available IoT modules. When it comes to prototyping — just another perfect, relatively cheap, easy-to-learn, and user-friendly minuscule magic module!

NodeMCU V1.0

The first generation of the NodeMCU Development Kit had the version number V0.9. The second generation had the version number V1.0, and this newer version used ESP-12E (not ESP-12), which comes with 4 MB of flash memory. The new version comes with the CP2102 serial chip (not CH340) and it works really well and without a hassle. However, I noticed that, when it comes to many Chinese online vendors, there’s a blurring mix-up of generation and version names. The common name used by them for version 1.0 is V2, and most of those V2 boards are fabricated by or at least marked with “Amica.” Technically, it’s “NodeMCU V1.0 with ESP-12E module!”

nmcu-p2

nmcu-p3

NodeMCU First Run

NodeMCU is a complete environment of hardware and software for IoT prototyping based on the Lua language. You can connect NodeMCU to your computer through a standard USB interface for power, programming, and debugging. Before using NodeMCU V1.0 for the first time, install the requisite USB driver (CP210x) on the operating system of your computer:
Download it from: http://www.silabs.com/products/mcu/

Now you can test your NodeMCU in Lua shell. As this calls for an appropriate terminal software, download PuTTY onto your computer: http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

nmcu-p4

Next, connect NodeMCU, run PuTTY to enter its Lua shell, and enter the test code to test the onboard LED in NodeMCU (also see following images). If everything is okay, you should able to connect NodeMCU with PuTTY, enter Lua shell, and test the on/off functions of the onboard blue indicator. If NodeMCU has no response in the PuTTY terminal, try to press the RST button on NodeMCU.

> gpio.mode(0, gpio.OUTPUT)
> gpio.write(0, gpio.HIGH)
> print(gpio.read(0))
1
> gpio.write(0, gpio.LOW)
> print(gpio.read(0))
0
>

nmcu-p5

nmcu-p6

This simple tutorial will show you how to use NodeMCU V1.0 for the first time. The steps are pretty simple to follow and should get your NodeMCU board running in less than 15 minutes. In upcoming articles, I will adapt new design ideas to implant NodeMCU at the heart of fascinating IoT systems. See you all in succeeding projects.

NodeMCU Links

Wikipedia Article on NodeMCU: https://en.wikipedia.org/wiki/NodeMCU
Offical NodeMCU Website: http://www.nodemcu.com/index_en.html
Github Repository for NodeMCU Firmware: https://github.com/nodemcu/nodemcufirmware
Github Repository for NodeMCU Hardware: https://github.com/nodemcu/nodemcudevkit

NodeMCU & Arduino IDE

Did you know? It’s very easy to use the Arduino IDE to program your NodeMCU, a great starting point for Arduino lovers to familiarize themselves with the technologies surrounding the IoT. Note that when you use the NodeMCU board with the Arduino IDE, the Lua firmware will be deleted and replaced by the sketch uploaded by you. If you want to use the Lua SDK again, it will become necessary to “flash” the firmware again.

The NodeMCU programming can be as easy as in Arduino. The major difference is in the pin assignment of the NodeMCU board. Ready? Then follow these steps:

  • Run the Arduno IDE
  • Open the “Preferences” window and type the indicated address in the “Additional Board Manager URLs:” http://arduino.esp8266.com/stable/package_esp8266com_index.json
  • In the “Tools” menu, configure your board “NodeMCU 1.0 (ESP-12E Module)”
  • Now just proceed as the Arduino: Start your sketching!

nmcu-p7

Shown next is an example code to realize a “breathing LED” on NodeMCU, taken from Arduining.com:

#define LED D0 // Blue LED in NodeMCU at pin GPIO16 (D0).
#define BRIGHT 350 //max LED intensity (1‐500)
#define INHALE 1250 //Inhalation time in milliseconds.
#define PULSE INHALE*1000/BRIGHT
#define REST 1000 //Rest Between Inhalations.
void setup() {
   pinMode(LED, OUTPUT); // LED pin as output.
}
void loop() {
   //ramp increasing intensity, Inhalation:
   for (int i=1;i<BRIGHT;i++){
      digitalWrite(LED, LOW); // turn the LED on.
      delayMicroseconds(i*10); // wait
      digitalWrite(LED, HIGH); // turn the LED off.
      delayMicroseconds(PULSE‐i*10); // wait
      delay(0); //to prevent watchdog firing.
   }
   //ramp decreasing intensity, Exhalation (half time):
   for (int i=BRIGHT‐1;i>0;i‐‐){
      digitalWrite(LED, LOW); // turn the LED on.
      delayMicroseconds(i*10); // wait
      digitalWrite(LED, HIGH); // turn the LED off.
      delayMicroseconds(PULSE‐i*10); // wait
      i‐‐;
      delay(0); //to prevent watchdog firing.
   }
   delay(REST); //take a rest...
} 

No Comments

Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?