Post topics, source code that relate to the Arduino Platform

User avatar
By abellisco
#92816 esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header: a possible solution

Summary:
I'm sure there is no single cause for the error, as could be seen in the amount of mentions to it on the Web.
If you already tried the more basic checks (cables, board selection, etc) then the procedure suggested here is based on a minor modification to be done in the esptool.py program.
Some previous tests are proposed to identify if the solutions applies (or not) to the problem you may have.
The esptool.py program allows to define some options in its command line (see --before option, https://github.com/espressif/esptool):
'default_reset',
'no_reset',
'no_reset_no_sync'

You can try with a simple command 'chip_id':
1st try: --before default_reset
$ python esptool.py -p /dev/ttyUSB0 --before default_reset chip_id
(if result:)
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

if this is what you get, then try:

2nd try: --before no_reset
$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x00d4d1a7
Hard resetting via RTS pin...

if it works, then this solution may apply to the problem you have:

Modify esptool.py, located at .arduino15/packages/esp8266/3.0.3/tools/esptool, Line 511 (if the Esp8266 board was installed using the Board manager)

##original code
def connect(self, mode='default_reset', attempts=DEFAULT_CONNECT_ATTEMPTS, detecting=False):
""" Try connecting repeatedly until successful, or giving up """
print('Connecting...', end='')
sys.stdout.flush()
last_error = None

try:
for _ in range(attempts) if attempts > 0 else itertools.count():
last_error = self._connect_attempt(mode=mode, esp32r0_delay=False) ## line1 to modify
if last_error is None:
break
last_error = self._connect_attempt(mode=mode, esp32r0_delay=True) ## line2 to modify
if last_error is None:
break
finally:

## modified code
try:
for _ in range(attempts) if attempts > 0 else itertools.count():
last_error = self._connect_attempt(mode='default_reset', esp32r0_delay=False) ## line changed
if last_error is None:
break
last_error = self._connect_attempt(mode='no_reset', esp32r0_delay=True) ## line changed
if last_error is None:
break
finally:

Save it, and now try again to upload your Arduino sketch.

In the attachment you can find the detailed summary of the tests performed to reach the conclusion of the solution proposed here, as well as traces of the commands used.

Hope is helps
Abel
You do not have the required permissions to view the files attached to this post.