Arduino upload error

error: espcomm_upload_mem failed

The upload tool could not sync with the ESP8266. It tried to open the port, found no answer, and gave up.

  • Upload error
  • 4 common causes
The message

What the Arduino IDE prints

Output window
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
Failed uploading: uploading error: exit status 2

The sketch compiled. The fault is the connection or the chip not being in flash mode.

Causes

The 4 usual causes in order

1The wrong port or the wrong board is selected

espcomm talks to the port you chose, at the speed of the board you chose.

  1. Pick the port that appears when you plug the board in.
  2. Pick the board you have, such as NodeMCU 1.0 (ESP-12E Module) or Generic ESP8266 Module.

2GPIO0 is not low during the upload

Bare ESP-01 and ESP-12 modules need GPIO0 pulled low to enter flash mode. A NodeMCU does this by itself.

  1. On a bare module, connect GPIO0 to GND, reset, upload, then remove the wire.
  2. On a NodeMCU, hold FLASH while the upload connects, then let go.

3The upload speed is too high

Cheap cables and long wires lose bytes at high speeds.

  1. In Tools, set Upload Speed to 115200 or lower.

4Not enough power, or no driver

The module draws bursts of current when it connects to WiFi, and a sagging supply resets it.

  1. Power a bare module from a stable 3.3 V supply, not from the 3.3 V pin of an Uno.
  2. Install the driver for the USB chip, a CH340 or CP210x, on Windows.
On a real board

What to do at the bench

Mokxi's Upload to board writes to an ESP8266, such as a NodeMCU or a D1 mini, from Chrome or Edge, through the same ROM bootloader esptool talks to, so the same fixes apply.

Run the sketch in Mokxi before you blame the board. If it builds and runs there, the code is fine and the problem is the connection to the real board.

Test the sketch in Mokxi first

Run the sketch here before you blame the board. If it builds and runs in Mokxi, the code is fine and the fault is the connection to the real board. Mokxi never uploads in a simulation, so it cannot raise this error itself.

A sketch to try first
void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println("blink ready");
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Run it in Mokxi

FAQ

Questions and answers

What is espcomm?

The old upload tool of the ESP8266 Arduino core. Newer versions of the core use esptool and say "Failed to connect to ESP8266".

Why does a bare ESP-01 need GPIO0 low?

The chip reads GPIO0 at reset. Low means flash mode. A NodeMCU has a button and a circuit that do it for you.

Is it my code?

No. The code compiled. The error comes before anything is written to the chip.