Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial

501,463

424

137

Posted

Introduction: Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial

NodeMCU Dev Board is based on widely explored esp8266 System on Chip from Expressif. It combined features of WIFI accesspoint and station + microcontroller and uses simple LUA based programming language. ESP8266 NodeMCU offers-

--Arduino-like hardware IO

--Event-driven API for network applicaitons

--10 GPIOs D0-D10, PWM functionality, IIC and SPI communicaiton, 1-Wire and ADC A0 etc. all in one board

--Wifi networking (can be uses as access point and/or station, host a webserver), connect to internet to fetch or upload data.

--excellent few $ system on board for Internet of Things (IoT) projects.

Recently, there has been interest in programming ESP8266 systems using Arduino IDE. Programming, of ESP8266 using Arduino IDE is not very straight forward, until it is properly configured. Especially because, the Input and output pins have different mapping on NodeMCU than those on actual ESP8266 chip.

I had request about showing how to program ESP-12E NodeMCU using Arduino IDE. I struggled myself earlier in the beginning, so thought of making this Instructable for beginners. This is quick guide/tutorial for getting started with Arduino and ESP8266 NodeMCU V2 ESP-12Ewifi module. (I think, this method can be used for other NodeMCU boards too. (or only ESP8266 boards, but with necessary hardware modifications and using FTDI modules for programming- not covered in this tutorial because, this is only for NodeMCU dev boards).

This Instructable gives quick intro to-
1) Installing Arduino core for ESP8266 WiFi chip in Arduino IDE and Getting started with sketches written using Latest stable Arduino IDE 1.6.7

2) Run/modify basic LED blink sketch to blink onboard LED and/or externally connected LED at pin D0 or GPIO-16 as per the pin configuration mentioned here and here.

NOTE- To use NodeMCU V1 or V2 or V3 dev boards using Arduino IDE, we do not need to flash it with firmware using nodemcu flasher. It is required only if we intend to program NodeMCU using Lua script with esplorer etc.

I have other video published on getting started with NodeMCU and flashing NodeMCU firmware on following link https://www.youtube.com/watch?v=x7GzK7zHKOk

**Arduino logo and NodeMCU logo are their respective trademarks- logos shown in above image were taken from -https://github.com/nodemcu and https://www.arduino.cc/en/Main/Software

Step 1: NodeMCU ESP-12E Pin Mapping

First and foremost word of - CAUTION !

* The ESP8266 chip requires 3.3V power supply voltage. It should not be powered with 5 volts like other arduino boards.

* NodeMCU ESP-12E dev board can be connected to 5Vusing micro USB connector or Vin pin available on board.

* The I/O pins of ESP8266 communicate or input/output max 3.3V only. i.e. the pins are NOT 5V tolerant inputs.

In case you have to interface with 5V I/O pins, you need to use level conversion system (either built yourself using resistor voltage divider or using ready to use level converters (e.g. these ones adafruit or aliexpress etc.).

-------------------------------------------------------------------------------------------------------------------------------------------------

The pin mapping of NodeMCU dev board are different from those of ESP8266 GPIOs. Attached images gives mapping of pins, source of images.

More information about pins is available on following links:

* Github - NodeMCU

* Github-esp8266/Arduino

Step 2: Installing Arduino Core for NodeMCU ESP-12E Using Arduino Boards Manager

As shown in the image, Copy the .json link with latest stable release of NodeMCU package from Github page here.

The link should look something like this-

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Step 3: Insert Link for .json NodeMCU Package Files Into Arduino IDE

Paste the copied link and insert it in Arduino IDE using following sequence-

File menu - Preferences-

Paste copied link into the area shown in black box in above image. Close and restart the Arduino IDE.

Step 4: Tools - Boards Manager

Tools - Boards managerand search for ESP8266 and install the libraries/files given under heading ESP8266 by ESP community.

Restart the Arduino IDE once again.

Step 5: Selecting NodeMCU Board in Arduino IDE

Go to Tools - Boards (scroll down the list of boards) - Select NodeMCU 1.0 ( ESP-12EModule).

Select the Port number at which you have connected nodeMCU. Rest of the settings can be left to default values.

Step 6: LED Blink - Connections for External LED

We will be connecting external LED directly to GPIO16 or D0 pin of NodeMCU (no need of external current limiting resistor). This is the pin number for onboard LED or BUILTIN_LED (in my case it is blue LED - some boards might have green or red LED).

Step 7: LED Blink - Example Sketch

Go to File - Examples - ESP8266 - Blink

In my video, I have modified the sketch to blink LED faster, but you can leave as it is and just upload the sketch to ESP and there you go... the On-board LED blue and external LED red starts blinking alternately at every second.

Congratulations for successful configuration of Arduino IDE for ESP8266 NodeMCU dev boards.

Note- In case, if Arduino IDE version 1.6.7 fails to work for you, try to go back to arduino 1.6.5 or backwards. (I have heard, some NodeMCU boards have issues with latest versions of Arduino IDEs and going to earlier versions of Arduino IDE solves the problems).

Good luck for fun with this amazing system on board.....

Helpful links-

https://github.com/esp8266

https://github.com/esp8266/esp8266-wiki/wiki

https://github.com/esp8266

http://nodemcu.com/index_en.html

https://nodemcu.readthedocs.org/en/dev/

My Doit NodeMcu Lua ESP8266 ESP-12E WIFI Development Board was from Banggood.com

9 People Made This Project!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • First Time Author Contest 2018

    First Time Author Contest 2018
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
user

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

Tips

Questions

112 Comments

user

i can't compiling every time i get this error: Arduino: 1.6.13 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)" Board nodemcuv2 (platform esp8266, package esp8266) is unknown Error compiling for board NodeMCU 1.0 (ESP-12E Module). This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. can you help me
______________________
https://9apps.ooo/ 
https://vidmate.vip/ 
https://getmobdro.com/

What if we want to connect multiple sensors who needs 5V supply? and also want to ask how we are supposed to power the nodemcu without connecting it with computer with a data cable?

about connecting to external supply you can use battery power pack and connect via microusb (5v) or using Vin pin (3.3v). applying more than 3.3v directly to any gpio pins will damage esp8266.

you cannot apply more than 3.3v on any Gpio. if you want to use 5v sensors then use voltage divider for level conversion Or get level converter modules from ebay etc.

Hi

I would like to turn on 2 GPIO with one command. Could you suggest how I might do that please (for motor controls)

Thank s

just declare two gpio pins and you are done.

Hi after uploading the sketch can i plug the board to an electrical output with an adapter and the sketch will run as with the pc?

yes you can connect to external power supply through micro usb port (5v) or through Vin pin (3.3v).

Can I upload code to NODEMCU by connecting USB cable from Arduino IDE, or do I need to provide a power supply and then connect the code? I have searched a lot but did not find anything relevant. Found this and I hope this helps, Thanking you in advance.

yes u can. do not supply extra vcc when usb is connected to pc.