Getting Started With NodeMCU (All in One Guide)

Published

Introduction: Getting Started With NodeMCU (All in One Guide)

About: I love DIY Electronics

NodeJS is a good microcontroller to get started with IoT (Internet of Things) related projects. For less than 5 dollars, you get an Arduino compatible board with on board WiFi module. At the heart of the NodeMCU runs an ESP8266-12 SoC and It is programmed in its own language LUA script. LUA script is similar to programming with JavaScript, beside LUA it can also be programmed in C and Python.

In this instructable I'm going to show you how to get started with creating projects with the NodeMCU. This instructable will show you how to program the NodeMCU using the arduino IDE and mcirco-python. And upload and run a few test programs.

Step 1: Tools and Components

Here is the list of components required to get started with the NodeMCU,

Hardware Components

  • NodeMCU
  • BreadBoard
  • MicroUSB
  • LEDs
  • 330 Ohm Resistor
  • A Cup of Coffee (Helpful when you wait for the Software tools to download)

Software Tools

  • Arduino IDE
  • LUA script Flasher

Step 2: Circuit

Before we start programming it lets get the hardware up and running, the circuit is very simple to build. All you need to do is connect the anode of the LED to digital pin 2 and the cathode to ground via a 220 ohm resistor, as shown in the picture. The circuit consists of one LED and a current limiting resistor connected in series with it.

The whole circuit is assembled on a breadboard hence no soldering skill are required. In the next few steps we will target uploading the code to the NodeMCU in 2 different tools and languages.

Step 3: The Arduino Style

To get started we need to download the arduino IDE and some necessary drivers.
The arduino IDE can be downloaded via this link - www.arduino.cc

After downloading the arduino IDE navigate to File => Preferences and in the additional boards URLs add the below URL

http://arduino.esp8266.com/versions/2.3.0/package...

After that navigate to the Tools>Boards>Board Manager and scroll down the list till you can find ESP8266 click on it and then hit install. Now you have setup the arduino IDE to work along with the node MCU.

Additionally you need to install the drivers if you are on a windows based computer. The drivers can be downloaded and install from the below link.

http://arduino.esp8266.com/versions/2.3.0/package...

Step 4: Arduino Uploading First Code

Once the driver is installed it is time to program the NodeMCU, for this select the NodeMCU 1.0 board from the Tools => Boards menu of the arduino IDE.

Now need to find the specific port to which the NodeMCU is connected to the computer. This can be found in device manager. In Tools => Ports make sure you select the right port as seen before.

Then Create a new sketch and paste the code below in the arduino IDE and hit upload.

void setup() {
pinMode(LED_BUILTIN, OUTPUT); //Set the Built in LED to pin to act as an output pin
pinMode(16, OUTPUT); //Set the D0 to pin to act as an output pin

}
void loop() { digitalWrite(LED_BUILTIN, LOW); //Turn off the LED digitalWrite(16, LOW); delay(1000); // Wait for a second digitalWrite(LED_BUILTIN, HIGH);//Turn on the LED digitalWrite(16, HIGH); delay(1000); // Wait for a second

}

The code will take a few minutes to upload and Then you should see the LED blink at the interval set in the code.

Step 5: Programming in Pyhton

The NodeMCU doesn't support a full python installation hence there is a smaller distribution of python named as micropython which is based of Python3. So you get all the basic functionality of Python3 on nodeMCU. You can learn more about micropython from the below URL.

https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html

Lets start with getting micropython running on the board, you can use nodemcu flasher tool to flash micropython on to you board. NodeMCU flasher tool can be downloaded from here. After flashing it use putty or any other serial monitor to open the right com port and now you should have a python terminal open you can python commands via this shell.

Makerspace Contest 2017

First Prize in the
Makerspace Contest 2017

Share

    Recommendations

    • Planter Challenge

      Planter Challenge
    • Oil Contest

      Oil Contest
    • Make it Move Contest

      Make it Move Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    8 Comments

    Nice instructable, but one question , why D0 is referenced as "16" I never use node MCU before only arduino , or where I can find the pin out making or the equivalences :p

    2 replies

    NodeMCU has its own pin definition file, also called pins_arduino.h. See (on windows) this directory:

    C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\variants\nodemcu\pins_arduino.h

    In there, you will see they have an own definition of LED_BUILTIN (mapped on GPIO 16 and not the more frequently used GPIO 13 in case of an Arduino) and they have also static defines for D0 - D10. There, you can see that for instance D0 is mapped on 16.


    Best,

    thank you so much, I will check that

    No absolute need for a resistor here (although it doesn't harm).

    NodeJS is a good microcontroller to get started with IoT (Internet of Things) related projects.

    I think its not "NodeJS".it should be "NodeMcu"

    Thank you for posting such a good tutorial

    Great tutorial and very clear photos :) Thanks for sharing!

    1 reply