Skip to content

Instantly share code, notes, and snippets.

@spacehuhn
Last active January 16, 2024 18:14
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save spacehuhn/b2b7d897550bc07b26da8464fa7f4b36 to your computer and use it in GitHub Desktop.
Save spacehuhn/b2b7d897550bc07b26da8464fa7f4b36 to your computer and use it in GitHub Desktop.
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.

@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