Getting Started with NodeMCU

Souman Roy
MetaInsights
Published in
4 min readFeb 11, 2017

--

Welcome to the exclusive tutorial on NodeMCU, let’s get started with your very first Internet of thing experience.

Short Intro…

What is ESP8266?

NodeMCU is an open source IoT platform. It’s ready to play around with the ESP8266, a tiny and inexpensive wifi system on a chip (SoC), which you can use to read data from sensors, connect to the internet or Connect Things EASY.!

Let’s get onboard .!

Prerequisites :
#1. NodeMCU ( ESP8266)
#2. USB Cable
#3. ESPlorer
#4. ESP8266 NodeMCU firmware from here

Step Zero : Update the Firmware

  1. Connect the NodeMCU via a micro-usb cable to the computer.
  2. Download and unpack esptool, either as a zip file using git clone.

git clone https://github.com/themadinventor/esptool.git

3. OS X already comes with python 2.7, but we need to install the pySerial dependency. Open a terminal and type

sudo python setup.py install

4. Download the latest NodeMCU firmware from here. Get the nodemcu_integer_*.bin file if you are unsure, for this example the newest version was nodemcu_integer_0.9.6-dev_20150704.bin

5. In Terminal Type

  • cd /Downloads/esptool

6. Flash the firmware using the following command.

sudo python esptool.py --baud 921600 --port /dev/tty.SLAB_USBtoUART write_flash -fm dio 0x00000 ~/Downloads/nodemcu_integer_0.9.6-dev_20150704.bin

7. If everything is done right you should see the following

Flashing the Firmware in Terminal

Congratulation you have successfully Updated the Firmware.!!!

Step One : Verify your firmware

Step: 1
Install the CP2102 driver from here. If using a different NodeMCU development board you might need different drivers.

Step: 2
Plugin the USB cable to the NodeMCU and then to the computer.

Step: 3
Open a terminal and type ls -l /dev/tty.*.
If everything went well you should see an entry similar to ls -l /dev/tty.SLAB_USBtoUART.

Step: 4
Download ESPlorer from here

Step: 5
In Finder, click the ESPlorer.jar to run the program (requires Java). If you get the message: “”ESPlorer.jar” can’t be opened because it is from an unidentified developer” then go to System Preferences –> Security & Privacy and click “Open anyway”

Explorer

Step: 6
Select the /dev/tty.SLAB_USBtoUART. and set the baud rate to 9600. Then click the “Open” buttonESPlorer configuration

Step: 7
Push the RST button on the ESP8266, it is right next to the micro-USB port

Step: 8
You should now see a message similar to
NodeMCU 0.9.5 build 20150403 powered by Lua 5.1.4
NodeMCU_connected

Congrats That’s it! We are now ready for programming the device

Final Step: Your First Program

The ESP8266 with the NodeMCU firmware executes Lua files. When booting the device it will look for a file called init.lua and execute this file. But first we will clear the device of every file

  1. In ESPlorer, click the format button to delete all files
  2. Next copy / paste the following code into the left hand box in ESPlorer
-- Config
local pin = 4 --> GPIO2
local value = gpio.LOW
local duration = 1000 --> 1 second


-- Function toggles LED state
function toggleLED ()
if value == gpio.LOW then
value = gpio.HIGH
else
value = gpio.LOW
end

gpio.write(pin, value)
end


-- Initialise the pin
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, value)

-- Create an interval
tmr.alarm(0, duration, 1, toggleLED)

2. Save the file as “init.lua”. This will automatically upload the file to the NodeMCU

3. Now the blue onboard LED should blink on and off every second. If you restart the device, it will load the init.lua file and keep on blinking

CONCLUSION

I have yet to explore the possibility of this little nifty device, but it looks promising. Using the development kit is much easier, but more expensive. The NodeMCU chips alone are less than half the price the development kit, but worth it for me.

--

--

Souman Roy
MetaInsights

Business Intelligence practitioner | Problem Solver | Founder MetaInsights, Solve for India