My esp8266 it´s having an error to connect when i write his code:A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header

CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp12e.htmlPLATFORM: Espressif 8266 (4.0.1) > Espressif ESP8266 ESP-12E
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:

  • framework-arduinoespressif8266 @ 3.30002.0 (3.0.2)
  • tool-esptool @ 1.413.0 (4.13)
  • tool-esptoolpy @ 1.30000.201119 (3.0.0)
  • tool-mklittlefs @ 1.203.210628 (2.3)
  • tool-mkspiffs @ 1.200.0 (2.0)
  • toolchain-xtensa @ 2.100300.210717 (10.3.0)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 48 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- CmdParser @ 0.0.0+sha.dcaa7ea
    |-- LittleFS @ 0.1.0
    |-- ota
    | |-- ArduinoOTA @ 1.0
    | | |-- ESP8266WiFi @ 1.0
    | | |-- ESP8266mDNS @ 1.2
    | | | |-- ESP8266WiFi @ 1.0
    |-- Wire @ 1.0
    |-- i2cscan
    | |-- Wire @ 1.0
    |-- mpu6050
    | |-- math
    | |-- i2cdev
    | | |-- Wire @ 1.0
    |-- magneto
    | |-- math
    |-- math
    |-- i2cdev
    | |-- Wire @ 1.0
    |-- ESP8266WiFi @ 1.0
    |-- bmi160
    | |-- i2cdev
    | | |-- Wire @ 1.0
    |-- bno055_adafruit
    | |-- math
    | |-- Wire @ 1.0
    |-- bno080
    | |-- SPI @ 1.0
    | |-- Wire @ 1.0
    |-- SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library @ 1.2.9
    | |-- SPI @ 1.0
    | |-- Wire @ 1.0
    |-- mpu9250
    | |-- math
    | |-- i2cdev
    | | |-- Wire @ 1.0
    Building in release mode
    Retrieving maximum program size .pio\build\esp12e\firmware.elf
    Checking size .pio\build\esp12e\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [==== ] 43.2% (used 35368 bytes from 81920 bytes)
    Flash: [==== ] 40.4% (used 422359 bytes from 1044464 bytes)
    Configuring upload protocol…
    AVAILABLE: espota, esptool
    CURRENT: upload_protocol = esptool
    Looking for upload port…
    Auto-detected: COM3
    Uploading .pio\build\esp12e\firmware.bin
    esptool.py v3.0
    Serial port COM3
    Connecting……_____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
========================= [FAILED] Took 30.13 seconds =========================

  • The terminal process “C:\Users\Thici.platformio\penv\Scripts\platformio.exe ‘run’, ‘–target’, ‘upload’” terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

Is COM3 the right port?

Have you put your board into bootloader mode by holding down the FLASH/BOOT button, pressing the reset button, and releasing the flash/boot button?

I don’t know where to change the port in studio code, normally i use the arduino ide to program, how can i see?

Just plug one esp at a time to be sure which one is being programmed if you have multiple,
and when programming esp, you need to press a button called “boot” if not wrong .
Do you use esp stand-alone module or on a dev board ?

https://docs.platformio.org/en/latest/projectconf/section_env_upload.html#upload-port

I have exactly the same issue. The same program can be uploaded with arduino IDE and I have the same error on VScode/platformio. Did you manage to find a solution?

And your ESP is for sure in bootloader mode?

how can I check?

What I know is that if I use the Arduino IDE it can flash the code without issue. while vscode cannot connect

========================================
platformio.ini
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
upload_protocol = esptool
upload_speed = 9600

==============Terminal output after succesful complilation======================
Retrieving maximum program size .pio\build\esp01_1m\firmware.elf
Checking size .pio\build\esp01_1m\firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [==== ] 41.0% (used 33608 bytes from 81920 bytes)
Flash: [==== ] 39.9% (used 303619 bytes from 761840 bytes)
Configuring upload protocol…
AVAILABLE: espota, esptool
CURRENT: upload_protocol = esptool
Looking for upload port…
Auto-detected: COM4
Uploading .pio\build\esp01_1m\firmware.bin
esptool.py v3.0
Serial port COM4
Connecting……_____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
======================================================================= [FAILED] Took 13.65 seconds =======================================================================

I feel like this has been discussed here before…

What Arduino IDE “Tools” menu settings do you have for upload?

Have you made 1000% sure to set the same upload method per documentation?

https://docs.platformio.org/en/latest/platforms/espressif8266.html#reset-method

Arduino Board configuration in vs code is identical to Arduino IDE “Tools” menu settings.
I cannot understand what is not working…

finally found the solution in another thread !

I added one line in platformio.ini
board_upload.resetmethod = nodemcu
now working perfectly.

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
board_upload.resetmethod = nodemcu
1 Like

But the board_upload.resetmethod documentation is exactly what I linked you to :cry:.

1 Like