Unable to upload ESP32 code - Invalid head of packet (0x1B)

Hello Adruino’ians!

So I built a prototype board for my circuit and installed the ESP32 board in my Arduino IDE as well. Connected the board, drivers get installed (Silicon labs CP210X USB to UART Bridge). I select ESP32 WROOM board and select the correct port.

Code gets compiled successfully. But when I try to upload the code, the IDE shows it is trying to connect to (Connecting …) and then i get the below error:

A fatal error as occurred. Failed to connect to ESP32: Invalid head of packet (0x1B)

Logs are as below:

“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\esp32-hal-time.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\esp32-hal-timer.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\esp32-hal-touch.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\esp32-hal-uart.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\libb64\cdecode.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\libb64\cencode.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\main.cpp.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\stdlib_noniso.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\wiring_pulse.c.o”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-ar” cru “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\wiring_shift.c.o”
Archiving built core (caching) in: C:\Users\Deepak\AppData\Local\Temp\arduino_cache_741343\core\core_f49bb90ee4eac19be0815af55bde9b20.a
Linking everything together…
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc” -nostdlib “-LC:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/sdk/lib” “-LC:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/sdk/ld” -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,–gc-sections -Wl,-static -Wl,–undefined=uxTopUsedPriority -u __cxa_guard_dummy -u __cxx_fatal_exception -Wl,–start-group “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\sketch\PowerMeter.ino.cpp.o” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\libraries\SPI\SPI.cpp.o” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647\core\core.a” -lgcc -lopenssl -lbtdm_app -lfatfs -lwps -lcoexist -lwear_levelling -lesp_http_client -lprotobuf-c -lhal -lnewlib -ldriver -lbootloader_support -lpp -lfreemodbus -lmesh -lsmartconfig -ljsmn -lwpa -lethernet -lphy -lfrmn -lapp_trace -lfr_coefficients -lconsole -lulp -lwpa_supplicant -lfreertos -lbt -lmicro-ecc -lesp32-camera -lcxx -lxtensa-debug-module -ltcp_transport -lmdns -lvfs -lmtmn -lesp_ringbuf -lsoc -lcore -lfb_gfx -lsdmmc -llibsodium -lcoap -ltcpip_adapter -lprotocomm -lesp_event -limage_util -lc_nano -lesp-tls -lasio -lrtc -lspi_flash -lwpa2 -lwifi_provisioning -lesp32 -lface_recognition -lapp_update -lnghttp -lspiffs -lface_detection -lunity -lesp_https_server -lespnow -lnvs_flash -lesp_adc_cal -llog -ldl_lib -lsmartconfig_ack -lexpat -lfd_coefficients -lm -lmqtt -lc -lheap -lmbedtls -llwip -lnet80211 -lesp_http_server -lpthread -ljson -lesp_https_ota -lstdc++ -Wl,–end-group -Wl,-EL -o “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.elf”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/gen_esp32part.exe” -q “C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/partitions/default.csv” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.partitions.bin”
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\2.6.0/esptool.exe” --chip esp32 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB -o “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.bin” “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.elf”
esptool.py v2.6-beta1

Using library SPI at version 1.0 in folder: C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\libraries\SPI
“C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-size” -A “C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.elf”
Sketch uses 249472 bytes (19%) of program storage space. Maximum is 1310720 bytes.
Global variables use 13628 bytes (4%) of dynamic memory, leaving 314052 bytes for local variables. Maximum is 327680 bytes.
C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\2.6.0/esptool.exe --chip esp32 --port COM24 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/partitions/boot_app0.bin 0x1000 C:\Users\Deepak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1/tools/sdk/bin/bootloader_qio_80m.bin 0x10000 C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.bin 0x8000 C:\Users\Deepak\AppData\Local\Temp\arduino_build_430647/PowerMeter.ino.partitions.bin
esptool.py v2.6-beta1
Serial port COM24
Connecting……_____

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x1B)
A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x1B)

I did a search but I couldn’t find anything with this above error.

Any idea what might be wrong? I’m on Arduino 1.8.8 IDE.

Regards,
Deepak

Here’s what I tried:

  1. Pressing boot button as soon as I click on Upload on the IDE
  2. Pressing the “BOOT” button when I see “Connecting …” on the Arduino IDE
  3. I connected a 100nf capacitor across the BOOT button (with difficulty) as per A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header · Issue #333 · espressif/arduino-esp32 · GitHub

I still can’t upload the sketch. This time I get the attached timeout error.

Any more ideas?

Regards,
Deepak