Getting started with NodeMCU development board for IoT




PREETI BHAKTA & SANI THEO

Since Internet of Things (IoT) projects are now quite popular, I recently bought a NodeMCU board to try IoT application development. The NodeMCU development board is an open source board based on ESP8266EX microcontroller with integrated Wi-Fi transceiver. Uploading programs to NodeMCU from any computer via microUSB port is very easy as it supports several programing languages. This makes NodeMCU a smart choice to play with the IoT.

Here I explain how to get started with NodeMCU board using some common tools including Arduino, PuTTY, LuaLoder and ESPlorer.

NodeMCU versions

NodeMCU versions

NodeMCU board comes in two popular versions: NodeMCU v0.9 with ESP12, and NodeMCU v1.0 with ESP12E (refer Fig. 1). NodeMCU v1.0 is the current version, which is not only breadboard-ready but also has some extra GPIOs (Fig. 2).

NodeMCU v1.0 pinouts

NodeMCU v1.0 pinouts




First, run NodeMCU and Lua

Most NodeMCU boards come with updated Lua firmware for operating in Windows platform. If it’s not included in your board, first refer to Firmware Flashing in the next section. Before using NodeMCU board, you need microUSB driver for Windows PC. Download driver from http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx, and install it in your Windows PC. Next, connect NodeMCU board to the computer through USB interface. Fig. 3 shows ‘Device Manager’ window of Windows 7 (x64) showing connected port of NodeMCU as COM35 here.

Windows Device Manager

Windows Device Manager

Now, you can test the onboard LED in Lua shell. The on-board blue LED (GPIO16 –DO) signals execution of the procedure. Before this, also download and install the PuTTY terminal software in your computer.

READ  A useful and simple IO Shield for Arduino

With NodeMCU connected to your PC, run PuTTY to get into its Lua shell.

Lua shell window

Lua shell window

If NodeMCU is not detected by the software, press its reset (RST) button. Once NodeMCU is detected, enter the following code in the Lua shell window (refer Fig. 4) to test the onboard LED:

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

If everything is okay as per the hardware configuration, “gpio.write (0, gpio.HIGH)” turns off the LED, and “gpio.write (0, gpio.LOW)” turns on the LED. In the Lua shell window, the first line seems like some garbage data. This is usual, you just have to ignore that.

Actually, these are random characters sent at a different baud rate but appear as garbage at normal rates.

NodeMCU with Arduino IDE

NodeMCU can be easily programmed through Arduino IDE (1.6.9). Here is the code to change the onboard blue LED to blink like a breathing LED:

// Breathing LED on NodeMCU v1.0
(Breathing.ino)
// Arduino IDE 1.6.9
// Based on a code published in
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); // 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); // prevent watchdog firing
}
delay(REST); //take a rest
}

To program NodeMCU in Arduino IDE, install esp8266 board (ESP8266 core for Arduino) to Arduino IDE by following these simple steps:

READ  Programming ATtiny85 with Arduino Uno

1. Open Arduino IDE and select ‘Preferences’ via ‘File’ menu
2. Type http://arduino.esp8266.com/stable/package_esp8266com_index.json in the field for ‘Additional Boards Manager URL’
3. Select ‘Boards Manager’ from ‘Tools’ menu
4. Under ‘Boards Manager,’ scroll until you find ‘esp8266’ board
5. Select the latest version and install
6. Select the board via ‘Tools’ menu (see Fig. 5)
7. Finally, copy, paste and then upload ‘Breathing.ino’ sketch

NodeMCU details on Arduino IDE

NodeMCU firmware flashing

Once the board is programmed through Arduino IDE, the original firmware will be erased. For some reason, if you want to restore the original firmware with Lua shell, you should flash the firmware again.

NodeMCU Flasher (https://github.com/nodemcu/nodemcu-flasher) is a popular firmware flash tool for Windows platform. After downloading and installing NodeMCU Flasher, download the latest NodeMCU firmware (https://github.com/nodemcu/nodemcu-firmware/releases).

At the time of writing this article, there are two versions for each firmware: integer (which supports only integer operations) and float (which supports floating-point calculations). From the performance point of view, the integer version is better. Here, the firmware (.bin) required is nodemcu_integer_0.9.6-dev_20150627.

The steps to flash the firmware using NodeMCU Flasher are:

1. Connect the board to the computer through USB interface
2. Open NodeMCU Flasher. In ‘Config’ menu, add the nodemcu bin file on 0x00000 column (refer Fig. 6(a) and (b))
3. Press ‘Flash’ button under ‘Operation’ menu (Fig. 6(b)), and wait

 

 

Read More Detail : Getting started with NodeMCU development board for IoT




Leave a Comment

*
= 3 + 0

(Spamcheck Enabled)

Read previous post:
DIY-Arduino-Nano-multimeter
DIY Arduino Nano multimeter with LiPo battery, charger and more

Arduino enthusiasts and makers searching for a new project to keep them busy this weekend may be interested in a new...

Close
Scroll to top