Flashing Wemos D1 Mini with ESPHome: Unexpected error: could not open port 'COM4': PermissionError(13, 'Access is denied.', None, 5)

I’m trying to flash my Wemos D1 mini with ESPHome to control my Garage door and I’m getting this error:

Unexpected error: could not open port ‘COM4’: PermissionError(13, ‘Access is denied.’, None, 5)

then followed by this error:

Unexpected error: ESP Chip Auto-Detection failed: Failed to connect to Espressif device: Timed out waiting for packet header

I’ve spent the last couple of hours on Google trying to figure out the fix by installing drivers etc, but nothing’s working. I’ve also tried flashing another Sonoff Basic that I had lying around and the same problem is happening, so I don’t think it’s the board.

I’m attempting this on a windows machine, using the flash tool and my code is the following

esphome:
  name: esphome_garage_door
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: 'xxx'
  password: 'xxx'
  fast_connect: on
  
api:

ota:

web_server:
  port: 80

logger:

binary_sensor:
- platform: gpio
  pin:
    number: GPIO13
    mode: INPUT_PULLUP
    inverted: False
  name: "Garage Door Sensor"
  device_class: garage_door
  filters:
    - delayed_on: 20ms

switch:
- platform: gpio
  id: relay
  pin:
    number: GPIO5
    inverted: False
  restore_mode: ALWAYS_OFF
- platform: template
  name: "Garage Door Switch"
  icon: "mdi:garage"
  turn_on_action:
  - switch.turn_on: relay
  - delay: 1s
  - switch.turn_off: relay
- platform: restart
  name: 'Garage Door REBOOT'


status_led:
  id: status_light
  pin:
    number: GPIO2

Has anyone overcome this?

Change usb cable.
Unplug, and plug back your Wemos D1 mini. Then, double-check that you’ve selected the right serial port in the Tools > Serial menu. Then, click the “ Connect/disconnect ” button to establish a serial communication.
This error might also mean that you have your serial port being used in another program (like a serial terminal or in the Arduino IDE).

Hi @Vlad, a lot of these things don’t apply to my view of the ESPHome flash tool (this is off Google images, I’m not at my machine right now):

If I take those bits away from your suggestion, it sounds as if you’re saying my USB UART connector could be defective? I’ve got this:
https://www.amazon.com.au/gp/aw/d/B072K3Z3TL?psc=1&ref=ppx_pop_mob_b_asin_title

I know this is an old topic, but I was able to get around this error on windows 10 (amd ryzen 5 chipset with asus mb) by simply running the x86 package instead of the x64.

Sorry if not an apporiate bump, but there really wasn’t an answer here.

1 Like

Can confirm this, worked for me too.

Have the same problem, but the x86 Version doesn’t work (Win 10 Pro with Intel i5-4570, MB HP 18E7)

for the people who are still having this issue… i had this with my D1 mini V3. you should check if your soldering is good. ( mine had bad soldering, the header pins were not straight causing errors) i bent them straight retried the flashing. worked like a charm so for me it was a case of bad circuiting.

2 Likes

I was having this problem too, x86 didn’t work (permission denied). I removed the Wemos from the breadboard, reconnected USB and then it started flashing, so might be something to the header pins suggestion.