Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flash ESP8266 over an Arduino

How to flash your ESP8266 without a USB-Serial adapter but with an Arduino.

First be sure everything is connected correcly:

Arduino ESP82666
TX RX
RX TX
GND GND
GND GPIO-15
VCC (3.3V) VCC (3.3V)
12 GPIO 0
13 CH_PD (EN)

The last 2 pins can be changed in the code.

Or set them manually:

PIN Mode
CH_PD (EN) HIGH (3.3V)
GPIO-0 LOW (GND)

Then upload this to your Arduino:

int program_pin = 12;
int enable_pin = 13;

void setup()
{
  Serial1.begin(115200);
  Serial.begin(115200);
  pinMode(enable_pin, OUTPUT);
  pinMode(program_pin, OUTPUT);
  digitalWrite(program_pin, LOW);
  digitalWrite(enable_pin,HIGH);
}

void loop()
{
  while(Serial1.available()){
    Serial.write((uint8_t)Serial1.read());
  }

  if(Serial.available()){
    while(Serial.available()){
      Serial1.write((uint8_t)Serial.read());
    }
  }
}

This code will let the Arduino send every byte it gets from the PC over Serial to the ESP8266 and back.

So now you can flash your ESP with the esptool or the nodemcu-flasher over the COM-port of the Arduino.

@emirerdo
Copy link

emirerdo commented Oct 9, 2018

what is Serial1 here?

@Spoozy
Copy link

Spoozy commented Jun 8, 2021

what is Serial1 here?

i think it is the hardware debug serial

@0cool-design
Copy link

0cool-design commented Aug 17, 2022

what is Serial1 here?

#include <SoftwareSerial.h> 

SoftwareSerial Serial1( PIN , PIN ); // RX, TX

int program_pin = 12;
int enable_pin = 13;


void setup()
{
  Serial1.begin(115200);
  Serial.begin(115200);
  pinMode(enable_pin, OUTPUT);
  pinMode(program_pin, OUTPUT);
  digitalWrite(program_pin, LOW);
  digitalWrite(enable_pin,HIGH);
}

void loop()
{
  while(Serial1.available()){
    Serial.write((uint8_t)Serial1.read());
  }

  if(Serial.available()){
    while(Serial.available()){
      Serial1.write((uint8_t)Serial.read());
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment