Click here to Skip to main content
13,198,322 members (54,136 online)
Click here to Skip to main content
Add your own
alternative version

Stats

33.5K views
314 downloads
11 bookmarked
Posted 21 Jan 2016

Programming the ESP8266 (NodeMCU) with the Arduino IDE

, 21 Jan 2016
Rate this:
Please Sign up or sign in to vote.
Project with NodeMCU (ESP8266) to control an RGB LED using the Arduino Programming Language

Introduction

This is an introductory article for those who already know the Arduino platform and are starting the programming the ESP8266 module through the NodeMCU platform or any other microcontroller of the same category.

The ESP8266 Module

The ESP8266 module is a IoT device consisting of a 32-bit ARM microprocessor with support of WIFI network and built-in flash memory. This architecture allows it to be programmed independently, without the need of other microcontrollers like the Arduino, for example.

esp8266

The problem is that, to create a development environment  focused in the ESP8266, we need to build a circuit with other integrated components to facilitate the work. That's why several projects arose of boards that incorporate the ESP8266, from which we highlight the following:

In this article, we will use the NodeMCU board as an example, but the design can be easily adapted to any other ESP8266 platform.

The NodeMCU Platform

NodeMCU is a complete environment of hardware and software for IoT prototyping consisting of the following items:

  • Controller board consisting of a ESP8266 module
  • Micro USB Port to power (5 volts) and programming
  • 10 digital inputs GPIOs operating at 3.3V and an analog input GPIO to 1.8 V
  • Development kit based on the Lua language

NodeMCU

Advantages of NodeMCU platform relative to the Arduino

  • Low cost
  • Integrated support for WIFI network
  • Reduced size of the board
  • Low energy consumption

Disadvantages

  • Need to learn a new language and IDE
  • Reduced pinout
  • Scarce documentation

The NodeMCU programming can be as easy as in Arduino. The main difference is in the pinning of the board, described below:

There are 6 extra GPIOs. All of them can be programmed as PWM, I2C, 1-wire, except for GPIO16 (D0).

For details on the ESP8266 and NodeMCU, see the references at the end of the page.
The purpose of this article is to show how we can program the NodeMCU using the Arduino programming language because, in this way, we are greatly reducing the disadvantages that the platform offers.

Example Project with NodeMCU

The sample project that we will develop consists in to make an RGB LED blinking, alternating their basic colors (red, green, blue) within an infinite loop. Watch a video demonstration here.

Necessary Components

  • NodeMCU board
  • Led RGB
  • 3 x 220 ohms resistors (or approximated values)
  • Wire jumpers

Mounting Details

Mounting

Software Installation

  1. Before using the IDE, install the USB driver in the operating system, which may be the CH340 or CP2102, depending on the board version.
  2. Run the Arduino IDE. If it has not been installed, do so here: https://www.arduino.cc/en/Main/Software
  3. Open the Preferences window and type in the "Additional Board Manager URLs" the following address:    http://arduino.esp8266.com/stable/package_esp8266com_index.json
  4. On the Tools menu, configure your board according to the model you are using. The most common options are:
    1. Board: NodeMCU, according to its model
    2. CPU Frequency: 80 MHz
    3. Upload Speed: 115200

Ready? Now just do as the Arduino: Let's Sketch!

Note: When you use the NodeMCU board with the Arduino IDE, the Lua firmware will be deleted and replaced by the sketch. If you want to use the Lua SDK again, will be necessary "flashing" the firmware again.

The Sketch

/*
NodeMCU example: RGB Led blinking
2016 by José Cintra
wwww.josecintra.com/blog
*/

int redPin = D1, greenPin = D2, bluePin = D3;

void setup() {
  pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);
  }

void loop() {
  digitalWrite(redPin, HIGH); delay(500);
  digitalWrite(redPin, LOW); delay(500);
  digitalWrite(greenPin, HIGH); delay(500);
  digitalWrite(greenPin, LOW); delay(500);
  digitalWrite(bluePin, HIGH); delay(500);
  digitalWrite(bluePin, LOW); delay(500);
  }

Resources

Conclusion

In this article, we saw how to configure NodeMCU in  the Arduino IDE. In upcoming articles, we will adapt this design to use Bluetooth and Wi-Fi.

See you in the next project ...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

José Cintra
Software Developer
Brazil Brazil
José Augusto Cintra is a IT analyst, teacher and game developer.
Homepage: HTML Apps
Blog: www.josecintra.com/blog

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questionhave you consider to post this as a tip? Pin
Nelek6-Feb-16 23:43
protectorNelek6-Feb-16 23:43 
AnswerRe: have you consider to post this as a tip? Pin
José Cintra11-Feb-16 8:47
memberJosé Cintra11-Feb-16 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 21 Jan 2016
Article Copyright 2016 by José Cintra
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid