Intro: Getting Started With NodeMCU (ESP8266)
ESP8266 is a popular, powerful and versatile wifi chip from espressif systems, the platform is available in forms of breakout or development boards(like ESP12e, ESP01 etc) but connecting those to your desired sensor/computer is a huge pain since it requires 3.3V and needs an external FTDI module for uploading the code and of course is not breadboard friendly. Thankfully though, there's a better option with all the required peripherals embedded on a single board and that's what is a NodeMCU(there are other options too like, Wemos D1 mini and other Wemos boards, Adafruit huzzah etc. but nodeMCU is the most widely used board, it's the Arduino UNO of wifi boards)
Let's get started...
Step 1: What Is ESP8266?
The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and a very powerful industry standard microcontroller capability produced by Shanghai-based Chinese manufacturer Espressif Systems.
The chip first came to the attention of western makers in August 2014 with the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using Hayes-style commands. However, at the time there was almost no English-language documentation on the chip and the commands it accepted. The very low price and the fact that there were very few external components on the module, which suggested that it could eventually be very inexpensive in volume, attracted many hackers,engineers, developers and hobbyists to explore the module, chip, and the software on it, as well as to translate the Chinese documentation.
The ESP8285 is an ESP8266 with 1 MiB of built-in flash, allowing for single-chip devices capable of connecting to Wi-Fi.
The successor to these microcontroller chips is the ESP32(the topic of another instructable).
Step 2: What's on the NodeMCU Dev Board?
the whole board is built around ESP12E module. ESP12E itself is a difficult board, it's not breadboard friendly, pin headers can't be soldered, you need an adapter to make it breadboard friendly, a ftdi breakout board along with some external connections to finally program the board. NodeMCU solves these problems, It integrates all the required components on a single breadboard friendly plug and play ready to use board.
As shown in the picture, NodeMCU consists of:
- GPIO pins (General purpose input/output) to which you connect all tour sensors, LEDs, other breakout boards like motor shield, LCD, OLED displays etc. a thing to keep in mind is the GPIOs cannot tolerate anything above 3.6V, so if you give a 5V input signal, you'll end up frying your NodeMCU (more about GPIOs HERE ). one thing to note that, the maximum current that can be drawn from a GPIO is 12mA. Anything more than that leads to chip malfunctioning or not booting at all. you can power a few LEDs, maybe a relay module(not a relay) but you need to give external supply for things that drawing high current.
- CP2012 which replaces FTDI as a USB to serial interface, and makes programming the board way easier, just plug the board into your pc via a micro usb cable, bring the board in flash mode (press and hold the flash button, press reset button and finally release flash button).
- AMS1117 linear 3.3V regulator, since the board uses 3.3V.
- Power Pins for the basic stuff like powering other peripherals, powering the board externally, resetting the board externally(tying rst pin to ground resets the board)
- ESP12E of course with a rectangular metal can rf shield.
- on-chip antenna.
- onboard LED connected to GPIO2.
- reset and flash buttons
NodeMCU supports i2c, SPI, and Serial interfaces.
One important thing worth noting is that you need to level shift the 5v signals from other peripherals to 3.3v before feeding to the GPIO pins.
Step 3: Getting Started With Programming the Board Using Arduino IDE
As Arduino.cc began developing new MCU boards based on non-AVR processors like the ARM/SAM MCU and used in the Arduino Due, they needed to modify the Arduino IDE so that it would be relatively easy to change the IDE to support alternate toolchains to allow Arduino C/C++ to be compiled down to these new processors. They did this with the introduction of the Board Manager and the SAM Core. A "core" is the collection of software components required by the Board Manager and the Arduino IDE to compile an Arduino C/C++ source file down to the target MCU's machine language. Some creative ESP8266 enthusiasts have developed an Arduino core for the ESP8266 WiFi SoC that is available at the GitHub ESP8266 Core webpage . This is what is popularly called the "ESP8266 Core for the Arduino IDE" and it has become one of the leading software development platforms for the various ESP8266 based modules and development boards, including NodeMCUs.
Step 4: Setting Up Arduino IDE
- download and install the latest version of Arduino ide from www.arduino.cc.
- Open the preferences window from the Arduino IDE. Go to File > Preferences.
Enter http://arduino.esp8266.com/stable/package_esp8266... into the “Additional Board Manager URLs” field as shown in the figure below. Then, click the “OK” button.
Open boards manager. Go to Tools > Board > Boards Manager…
Scroll down, select the ESP8266 board menu and install “esp8266”
Choose your ESP8266 board from Tools > Board > NodeMCU 1.0
Select the Port number at which you have connected nodeMCU. Rest of the settings can be left to default values.
Step 5: Programming and Testing
After setting up the IDE, You're ready to program the board ...
you need to put the board into programming mode before uploading the sketch and to do so, just follow a simple step.
connect the board to your PC, Press and hold the flash button, press reset button and finally release flash button.
now, for the testing
navigate to file>examples>esp8266>blink.
It'll open a new window having the sketch(code) for blinking the onboard led.
select proper com port and board and click upload.
Press the reset button once after uploading finishes(to bring the NodeMCU out of the programming mode). The onboard led should start blinking showing success :) ...