Serial Monitor crashes after startup of ESP32

I’m using PlatformIO on VS Code (Windows) to upload and test code on a ESP32-CAM module.
To upload and to use the serial monitor I’m using an USB-to-TTL converter.

Compiling and uploading works perfect.
However the serial monitor crashes after startup/restart of the ESP32.

Here is the output of the serial monitor:

> Executing task in folder ESP32-Cam-Webserver: C:\Users\claus\.platformio\penv\Scripts\pio.exe device monitor <

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at
--- Miniterm on COM3  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

configsip: 0, SPIWP:0xee
mode:DIO, clock div:2
entry 0x400806ac

Exception in thread rx:
Traceback (most recent call last):
  File "C:\Users\claus\.platformio\python3\lib\", line 926, in _bootstrap_inner
  File "C:\Users\claus\.platformio\python3\lib\", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\claus\.platformio\penv\lib\site-packages\serial\tools\", line 445, in reader     
    data = or 1)
  File "c:\users\claus\.platformio\penv\lib\site-packages\serial\", line 257, in in_waiting    
    raise SerialException("ClearCommError failed ({!r})".format(ctypes.WinError()))
serial.serialutil.SerialException: ClearCommError failed (PermissionError(13, 'Zugriff verweigert', None, 5))

According to python 3.x - Read/Write value for some time,pyserial throws ClearCommError failed (PermissionError(13, 'Access denied', None, 5) - Stack Overflow and call to ClearCommError Failed this may be a hardware problem with the adapter or a software problem.

What I find interesting is that the bootloader messages appear fine, but as soon as it boots into your application code, the connection is being closed, presumably by the USB-TTL adapter.

  • What code are you uploading to the ESP32?
  • Which exact adapter are you using?
  • Can you try different ones if available?
  • Does the same error occur when using a blinky sketch?
  • Does your application attempt to drive GPIO pins which are connected to the USB-serial adapter, causing it to fail / detect a conflict and to close the connection?
  • Does the same occur when uploading the sketch via the Arduino IDE?