Introduction: Program Generic ESP8266 12e NodeMCU Board With Arduino IDE
The Generic ESP8266 ESP-12E NodeMCU Development Board with built-in USB port is widely available, and quite cheap. It offers wireless connectivity, USB connectivity, and a reasonably powerful MCU, all for a few dollars and a pretty small footprint. The type of board I'm talking about looks like the picture above.
This is an Instructable for how to use this type of Generic ESP8266 ESP-12E NodeMCU Development Board with the Arduino IDE through the built-in USB port.
Step 1: Download, Install, and Set Up the Latest Version of the Arduino IDE
If you don't already have it installed, Download the latest version of the Arduino IDE:
https://www.arduino.cc/en/Main/Software
Now run the install package to Install the IDE on your computer.
When the install is complete, run the IDE so we can set it up to include the ESP8266 boards. Once it's running, do the following steps:
- Go to File->Preferences
- In the Settings Tab of the Preferences Dialog, Copy the URL found below into the "Additional Boards Manager URLs:" textbox. If there is already one or more URL's in this box, add this new one to the end of the string, separated from the others by a comma. This tells the Arduino IDE where it can get the ESP board manager extensions for various ESP8266 boards.
- The URL is: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- If you don't have the "http://" at the beginning of this URL address, the Arduino IDE gives you a protocol error when you try to load the package in the Boards Manager.
- Now go to Tools > Board > Board Manager and Type "esp8266" in the filter box.
- You should see the "ESP8266 Community esp8266" package in the resulting list (it will probably be the only one there).
- Click on the "ESP8266 Community esp8266" package
- Use the version pulldown list at the bottom left to select a package version (use the latest)
- Click the Install button.
This should install the ESP8266 boards package into the Arduino IDE.
Step 2: Figure Out What COM Port Your Board Creates
Plug a USB cable into the ESP8266 board, and plug the other end into your computer.
Your system should report that you just inserted a serial COM port. You need to figure out which port number it shows up as:
- Check Windows Device Manager (right-click on the "My Computer" or "This PC" icon and choose "Manage" on the menu. Then choose "Device Manager" in the left pane.
- Expand "Ports (COM & LPT)" in the right pane.
- On the ports list, you should see a port for your board. If you don't know which one it is, you can unplug the board and plug it back in, and you'll see the port for it disappear and reappear.
- Mine came up as "Silicon Labs CP210x USB to UART Bridge (COM14), but yours will depend on your ESP8266 board and your computer. You don't need to worry about port settings here -- these will be set in the Arduino IDE later.
Remember which COM Port number your board is assigned to (for example COM4, COM11, COM14, etc.)
Step 3: Select the Board and Set Up the Board Parameters in the IDE
Now we need to select the right type of board in the Arduino IDE. In the Arduino IDE Tools Menu, Set up your parameters as follows:
Tools -> Board -> NodeMCU 1.0 (ESP-12E Module)
Tools -> Flash Size -> 4M (3M SPIFFS)
Tools -> CPU Frequency -> 80 Mhz
Tools -> Upload Speed -> 115200 (We'll see more about this in a minute...)
Tools-->Port--> (The port number we found in the Device Manager in the last step, COM4, COM14, or whatever.)
Step 4: We May Need to Find the Right Upload Speed...
Here, it gets a little tricky, because that 115200 Baud Upload Speed you just set may not be right for your board.
As far as I can tell, different brands of this board style will have different baud rates set by the boot loader that's already installed on the board.
The reference I used to learn how to do this said to use 921600 as the Upload Speed. That seemed to work fine for upload, but my sketch wouldn't run.
As it turns out, the Arduino IDE can't tell if the Upload Baud Rate is right, so it doesn't throw an error if you have the wrong baud rate set. So you THINK you're uploading, but all the board hears is garbage, so you haven't really flashed your program after all.
I found the correct baud rate for my board by trial and error. I downloaded the blink sketch with each available baud rate in turn until it started blinking. So later, when we get to Uploading the Blink Sketch, you may have to go through the Baud Rates until you find one that works.
I would try the 115200 Baud Rate first, because I believe you have a high chance of success with that one on the typical generic board.
Step 5: Test to See If Your Board Is Working at All...
There's a convenient thing about the boot loaders on these boards -- when you press the reset button, they send a little report out the USB port. This can be used to see that your Board is running and communicating. I'm not sure that all the available boards do this, but I think it's pretty common.
If you bring up the Serial Monitor from the Arduino IDE Tools Menu, and select the port for your board (the same port as before).
Then press the reset button on your ESP8266 board, you'll hopefully see that the board is trying to send you a message. It might look like trash, but if you see anything happen, that probably means the board is transmitting a short report.
So here we run into another fun baud rate idiosyncrasy:
I had to trial-and-error this baud rate too, and it turned out to be DIFFERENT than the Upload Speed baud rate. In my case, this serial debugging baud rate was 74880. The message my board sends when you reset it looks like this:
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld
So, if you're getting some squares and random characters in the serial monitor when you press reset, try all the baud rates available in the serial monitor until you see intelligible characters. If no baud rate works, your board may be using some oddball baud rate the the serial monitor doesn't support.
Once you see a report on reset, you know that the MCU on your board is up and running, and able to communicate.
If you don't see anything happen in the serial monitor when you press reset on the board, check that you are looking at the right COM Port in the serial monitor. If that's correct, and no baud rate works, check that the LED on the upper left corner of the metal ESP8266 Chip blinks when you reset. If so, the board is trying to transmit a message, so you may have a bad USB driver for the board. You'll have to research how to fix that.
If the board doesn't blink when you press reset, then either you have a bad board, or the boot loader in the board doesn't report on reset. Check into flashing the board with a new boot loader (more on this later).
Step 6: If You Think You Need to Flash a Boot Loader...
If you couldn't get the last step to give you a report on the serial monitor when you press reset, you might need to flash your board with a new boot loader. As I understand it, this is pretty easy, and you might be able to gain a greater amount of control over the settings of the board's baud rates as well by flashing the board.
MakerFocus (from whom I bought my boards) had some obscure instructions to "Download and run the 32 bit flasher exe at Github". I didn't do this, so I'm not much help on this part, and MakerFocus didn't provide much guidance on what this does for you or really how to do it, but here is the Github program they point to:
https://github.com/nodemcu/nodemcu-flasher
Read the readme file on that Github page to figure out how to use it. I've seen other references to this program as well, so I assume it works ok. The program is apparently written in Pascal, but there are compiled EXE's available so you don't have to try to compile it.
You can Download and run the compiled 32-bit Windows flasher program as an executable file at:
https://github.com/nodemcu/nodemcu-flasher/tree/ma...
-Or-
The compiled 64-bit Windows flasher program as an executable file at:
https://github.com/nodemcu/nodemcu-flasher/tree/ma...
If you try this and it works, or you learn something interesting, please let us know in the Comments.
Step 7: Find the GPIO Pin That Your Built-In LED Is Connected To...
Apparently, different versions of these boards have their built-in LED on different pins. I personally think the industry may have finally standardized this to GPIO-16, which is marked D0 on the top of the board -- at least for these AI-Thinker NodeMCU-style boards with the built-in USB port.
The LED's are hooked up between a GPIO pin and 3.3V, so when the GPIO pin is set as an output and is brought low, the LED lights up. This means you can check if it's on GPIO-16 (D0) by quickly grounding the D0 pin while the board is powered. If the LED lights up when you ground the pin, that you've found it.
A word about these pin numbers:
For reasons I don't understand, these boards have been marked with these "D" numbers similar to an Arduino Nano, but different. These "D" numbers are not logically ordered with the actual GPIO pins on the 8266 chip itself. The Arduino package for this board has defines for the "D" numbers that map any "Dx" to its proper GPIO number, as seen here:
static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
static const uint8_t D7 = 13;
static const uint8_t D8 = 15;
static const uint8_t D9 = 3;
static const uint8_t D10 = 1;
Step 8: Finally, Upload and Run the Blink Sketch...
To Upload and run a sketch on the board from the Arduino IDE:
- Create a blank sketch
- Copy the code below into it and save it.
- Hit the Upload button, and wait a couple of minutes for it to compile.
- It should automatically start uploading (or looking like it's uploading)
- The board will run the sketch automatically when it's done, if you've got the baud rate and the LED pin right.
- If the sketch doesn't run, try all the different upload baud rates until it does, as discussed earlier.
Here is the code for the Sketch:
//***********************************************************************************************
// ESP8266 Blink by Kevin Petrasek
// Generic NodeMCU-style ESP12e Board
// with the ESP8266MOD by AI-THINKER
// Blink the built-in blue LED on GPIO-16 (D0) pin.
/
/ The built-in LED on this style of generic boards is connected
// to GPIO16(as marked on the board bottom silkscreen markings),
// Which is marked D0 on the board's top silkscreen markings.
//***********************************************************************************************
//Here is a map of the "D" markings on the board vs. actual ESP8266 chip GPIO numbers
//static const uint8_t D0 = 16;
//static const uint8_t D1 = 5;
//static const uint8_t D2 = 4;
//static const uint8_t D3 = 0;
//static const uint8_t D4 = 2;
//static const uint8_t D5 = 14;
//static const uint8_t D6 = 12;
//static const uint8_t D7 = 13;
//static const uint8_t D8 = 15;
//static const uint8_t D9 = 3;
//static const uint8_t D10 = 1;
static const uint8_t LED_PIN = 16; //The LED is on GPIO-16 pin (D0)
void setup() {
pinMode(LED_PIN, OUTPUT); // Initialize the D0 pin as an output
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_PIN, LOW); // Turn the LED on by bringing the ouput pin to LOW voltage level
// the LED turns on because the other side of the LED is tied to 3.3V
// and sending this pin LOW sinks this side to ground.
delay(1000); // Wait for a second
digitalWrite(LED_PIN, HIGH); // Turn the LED off by bringing both leads to 3.3v
delay(2000); // Wait for two seconds, then loop
}
Step 9: Further Reading...
For further learning, Here is a link to the Arduino IDE Core on GITHub for the ESP8266 boards:
https://github.com/esp8266/arduino
Here's a link to the manual for the ESP8266 12E module itself:
https://www.kloppenborg.net/images/blog/esp8266/esp8266-esp12e-specs.pdf
Good Luck, and Happy Tinkering!


