Saturday, 3 September 2016

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

This could be the most advanced and economical of all the Arduino derivatives. Faster than Atmel and PIC32 based Arduino IDE. Slower than ARM but ARM based boards are too expensive and difficult to use. This ESP-12e is even equipped with Wifi, making it ideal for the IoT. Pricewise, it is the same as the cheapest Atmel 8-bit 16Mhz Arduino Nano.

You can get them here:

NodeMcu-Lua-V3 WIFI-development-board-based-on-the-ESP8266-Internet-of-things 

Original Link

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

by
Featured
Picture of 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

Picture of NodeMCU ESP-12E Pin mapping
NODEMCU_DEVKIT_SCH.png
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

Picture of 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

Picture of 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

Picture of Tools - Boards manager
esp8266boardsmgr.jpg
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

Picture of Selecting NodeMCU board in Arduino IDE
portno.jpg
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

Picture of LED blink - connections for external LED
NodemcuLEDBlinktestArduinoIDE_schem.jpg
20160208_012145.jpg
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

Picture of 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
Post a comment
Be nice! We have a be nice comment policy.
Please be positive and constructive.
5 days ago
I have the same error until I found some videos like this:
Some boards need flashing first with the tool presented on this video (my case with a no-name board), some don't (my case with an Amica board). After you've done the flashing procedure you'll be able to use Arduino IDE, putty, esp tools etc. Otherwise not. I use only Arduino IDE because I'm familiar with.
18 days ago
Hi i have error
esptool v0.4.9 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
setting board to nodemcu
setting baudrate from 115200 to 115200
setting port from /dev/tty.usbserial to /dev/cu.wchusbserial1420
setting address from 0x00000000 to 0x00000000
espcomm_upload_file
espcomm_upload_mem
opening port /dev/cu.wchusbserial1420 at 115200
tcgetattr
tcsetattr
serial open
opening bootloader
resetting board
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
resetting board
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
resetting board
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
trying to connect
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
serialport_receive_C0: C4 instead of C0
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
17 days ago
never heard or experienced such errors. not sure what might be causing this. but just quick guess is...have you selected correct nodemcu board in boards manager?
have you installed esp8266 arduino core libraries properly?
is your usb cable good?
lastly do not connect it to usb hub.
good luck.
17 days ago
HI
have you installed esp8266 arduino core libraries properly? yes i installed libraries.
is your usb cable good?- good
thanks
17 days ago
esp communication error is mostly encountered by me when usb cable is not good, esp is connected to usb hub, improper driver, wrong board selected while selecting board in arduino ide.
check if you can see usb device in Windows device manager, try to change baud rate of your usb port, use short usb cable , do not connect via usb hub.
last option would be, try first to program usin esptool or lua loader, if it doesn't work even there then probably something is wrong in your hardware or in communication port.
I have a video on my youtube channel about getting started with nodemcu using esptool.
good luck
5 months ago
good i'ble.Now after passing through everything ,
during uploading, i get this
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed.
what might be the reason , i am sure with the correctness of the serial port .
18 days ago
HI,
Very likely you have two (or more) Arduino-IDE/Serial monitor windows open.
Dave
5 months ago
I remember having this error at some point but cannot recall correctly what I did to resolve it..
do you have anything connected to io pins of ur esp? especially D0 , if so just remove it for a while during programming. secondly, esp are power hungry devices... my esp shows errors when several sensors/peripherals are powered directly through nodemcu. just as a test, first try upload sketch on a bare board.
I hope this helps a bit. good luck
5 months ago
check your com port number and settings.
5 months ago
if someone in the community could solve this,i would be grateful to them
3 months ago
Why is a current-limiting resistor not needed for the LED? The GPIOs are rated for 12mA and typical LEDs draw 20mA.
18 days ago
Looking at the schematic, you NEED a resistor, tho one onboard is only connected to the onboard LED.
3 months ago
no, you do not need to do anything with Rst or Flash buttons, to program.
3 months ago
it is not required for D0 pin since there is an onboard resistor, as far as I know.
for other pins we will need a resistor.
riaz.sulaimi made it!
20 days ago
Hi,
I have already setup and tested a weather iot using NodeMCU but now i need an external battery supply. My electronics knowledge is rudimentary at best but can i use a 9v snap jack cable connected to a jack to micro usb cable that is connected to the NodeMCU as a power supply? Will the ams1117 take care of the step down for the 3.3v or will that like totally fry my nodeMCU board?
19 days ago
I believe it should work by applying 9v through usb socket..but not sure. you also need to be very careful that you do not apply 9v to usb data pins.
other way is to apply 9v via Vin pin of nodemcu. to the best of my knowledge the voltage regulator should take care of stepping down voltage to 3.3v.
just a word of caution. ..I have confusion whether max voltage can be 5 v or 12v at Vin pin..because I read in some forums that we can apply max 5 v only to Vin pin. but my guess is 9v at Vin pin should work.
good luck.
19 days ago
Thanks Electromania! *Keeping fingers crossed *
20 days ago
Sir when i press compile bottom on Arduino ID it showing following
error--- Error Compiling for board Node MCU 1.0(ESP-12E Modul).
Board nodemcuv2 (platform esp8266,package esp8266) is unknown
Error compiling for board ModeMCU 1.0 (ESP- 12E Module)
please help me
19 days ago
do u see Nodemcu board in Boards Manager as shown in step 5.
If not, then seems you have not installed esp8266 core repositories as mentioned in previous steps.
secondly please remember to restart your Arduino IDE after installing esp8266 core libraries.
a month ago
I have the same problem (I think).
I do everything listed in the instructable, however when I plug the esp into a usb port, the IDE doesn't list it (no ports available). Am I missing a driver or something? I tried linux and windows.
If I randomly push the reset and flash buttons, both sometimes list a port, and I am able to upload a sketch, however when trying to open the serial monitor later, the port is no longer listed.
Someone please help :(
25 days ago
esp is power hungry device. if ur pc detects esp for some period and dissappears later then- i noticed this issue if the usb cable lenght is too long or not good quality like those Blue colored usb cables commonly supplied with most of the Chinese web suppliers. when I used my samsung or nokia phone cable such issues were solved.
if you cannot detect the nodemcu at all..evenin device manger in windows system then probably you will need appropriate drivers. I have given links to drivers used by me on my github page. I have tested those on win xp..win7 and win 8.1 pc...all work perfectly. please follow my videos on youtube about installation procedure. it is probably given in video of getting started with arduino nano... chip is same in both cases.. ch340 I guess.
a month ago
Hello, I have tried and tried to load my NodeMCU to the board manager according to your direction but the ESP COMM option does not appear in Board Manager section upon restart. Any suggestion? Let me know if you need any other info to help you understand my issue. Thanks.
a month ago
Are you stuck at Step 4 ?
if so, make sure you are putting correct link http://arduino.esp8266.com/stable/package_esp8266com_index.json in the arduino preferences. Which version of arduino IDE are you using ? Try first exactly 1.6.7 version like i have used. once it works on this, then you can upgrade your Arduino IDE to latest version. or try to go to 1.6.5 version. i have followed the steps given in my instructable on 3 different PCs and they have worked perfectly for WinXP, Win 8.1 and Win 7.
a month ago
Thanks a lot for your rapid reply. Pardon my ignorance but how can I roll back my IDE version from 1.6.11 to 1.6.7? The only way I can figure is to uninstall the IDE entirely but won't doing so lose my sketchbook?
a month ago
I generally take a copy of my Arduino folder libraries n sketchbook folder. then install arduino. later you can put back libraries n sketchbook folders.
a month ago
Hi,
I'd like to connect NodeMcu to my wifi and then when someone presses the button connected to NodeMCU that it triggers Raspberry Pi's script which runs Pushbullet notification that someone rang the doorbell and then takes the screenshot of the camera.
Second part with RPi I've done in Python and it's working fine, but only when pressing the button which is connected to RPi, now I'd like to get it wirelessly via NodeMCU which would somehow trigger over the wifi the RPi.
Is that possible, and how would you do it?
Thank you! :)
a month ago
I believe it should be possible to do what you said. I have not yet explored this further. You can try to send UDP data to rpi or use a web server on nodemcu and let rpi read it... these are just suggestions.
i have been able to connect rpi to nodemcu via udp..but still to be explored. In few weeks i will upload instructable on this. may be that might somehow help you.
a month ago
I also have a D1 that is having the same issue. Thanks again.
2 months ago
http://arduino.esp8266.com/stable/package_esp8266c...
i cant install this...i am getting error downloading message !
2 months ago
try link of github. you don't have to download manually. it will be done automatically.u just have to insert link into arduino ide as shown in step 2.
3 months ago
how to connect board arduino to nodemcu board?
4 months ago
I've been playing with an ESP12EV2 I got from Banggood and have struggled but been ultimately successful in creating a little web server that can turn the 2 LEDs on my board on and off and blink them. But success with the Arduino IDE had eluded me until I watched your video (so, Thanks!). I look at this little device as a bit of a treasure hunt. The actual developers are very stingy with information and the really detailed documents are in Chinese (which I do not read). So we hunt and peck and poke around and collaborate and try to make something work. I'm sure I can do cool things with one. There is only one thing that I cannot resolve: I cannot get my iPhone to reliably connect to the ESP when it is in SOFTAP mode. It will maybe connect once but then I have to erase the flash and re-load the code I have written. Then it will connect again, but only once. Eventually I will figure that one out too. Thanks again!
4 months ago
Thanks for the pinout & schematic. I am using an ESP-12 V2 I got on
banggood.com and it has two LEDs and I don't know how many you ESP has
because your schematic shows only one. On my boards, the one in the
middle is D0 / GPIO16. There is another that blinks when the board is
being flashed and that one is D4 / GPIO2. The pin mapping is a little
confusing because what the pinout calls D0 is GPIO16 and 16 for the
Arduino IDE. Likewise, D4 on the pinout is GPIO2 and 2 for Arduino.
Live and learn.
3 months ago
yes it is true...pinout differences between arduino and nodemcu and esp8266 gpio are all different. I too had lot of confusion in the beginning.
I have same board like yours and two leds onboard same like you. in sketch I just showed externally connected led because it is understood that there are two more leds onboard nodemcu, shown in video.
nevertheless, I always remain confused between pin mapping differences. so, as a quick guide I have given a table with pin mapping on my blog here...
http://theelectromania.blogspot.it/2016/02/how-to-program-esp8266-esp-12e-nodemcu.html?m=1

enjoy IoT...
3 months ago
your are absolutely right. I too believe this is like a intelligent black box... n probably it is much versatile n useful than what is generally mentioned on the suppliers website. documentation is scattered n confusing.
I think, not sure, your problem might be related to interfence from some other wifi devices...like router, mouse etc running at same channel as that of ur nodemcu. it took a month for me to realise that my newly purchased wireless mouse was interfering my all other wifi devices.
good luck...
4 months ago
i have nodemcu. first i connected nodemcu to router.after that i disconnect that router. after some time i connect nodemcu to other router which is not have internet connection . so my nodemcu is not connect that router...
so please give me solution for that as soon as possible
4 months ago
it should connect to otherone too... irrespective of whether it is connected to internet or not. please check your wifi ssid and password.
also try changing security type of router e.g. psk, tkip etc.
5 months ago
now im not able to access the port option itself to select the port
5 months ago
good to know... driver reinstalling worked.
you can skip connecting external led. just check if you Onboard led blinks.... if uploading is successful then it should work. are you putting correct pin no in your sketch?
5 months ago
check if you have drivers installed properly for usb to ttl converter you are using ...refer my latest instructable and youtube video where I have shown how to install drivers...
are you using nodemcu?
5 months ago
i am using node mcu
5 months ago
https://youtu.be/fZX9FQuNBdc

check this video for installing drivers...
5 months ago
What if you only have the esp-12 board and not the nodeMCU board? Like the image below without the DHT sensor, I can program the other board (on the white breakout board) with no problem.
Thanks in advance if anyone has any input, I also have the resistor between GPIO15 and ground on both boards.
5 months ago
Sorry, I have not understood your question, you say that you can program white board. And both boards not nodemcu. you can program White board using Arduino IDE and Black board cannot ?
I think it is straight forward to program is using Arduino as long as you have USB to TTL converter and you have made necessary pin connections.
5 months ago
I guess that was confusing, but I can program the 8266 12, but when I wire up the 8266 12-E, I am unable to program it, and the one time I was successful, it knocked all my other wireless devices offline when it connected to my wireless network.
5 months ago
sounds strange. did you try to reflash or reset your esp.
6 months ago
nodemcu board is the best on the market right now in my opinion. for price and what it can do, there is just nothing else out there to even compete.
6 months ago
great tutorial, really helpful thanks :)
7 months ago
Very informative...Thanks!

1 comment:

  1. Almost same with this article, this blog will show how to programming esp12e via Arduino IDE:
    http://engineer2you.blogspot.com/2017/05/esp12e-arduino-programming.html
    Thanks

    ReplyDelete