ESP8266 Wemos D1 R2 PermissionError 13 when uploading

I have found that when the driver installation gets into this state, it can be solved by uninstalling and then reinstalling the drivers. After that, the "roll back" option should be enabled.

I'll provide instructions you can follow to do that:

  1. Close Arduino IDE if it is running.
  2. Connect the Arduino board to your computer with a USB cable.
  3. Open the Windows Device Manager.
  4. Select View > Devices by type from the Device Manager menus.
  5. Open the "View" menu.
  6. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  7. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  8. You should see a port identified as "USB-SERIAL CH340 (COMn)" under the "Ports (COM & LPT)" section (where "COMn" is some serial port e.g., COM4). Double click on that item.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  9. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  10. Click the "Uninstall Device" button.
    The "Uninstall Device" dialog will open.
  11. Check the box next to "☐ Attempt to remove the driver for this device.".
  12. Click the "Uninstall" button.
    The "Uninstall Device" and "USB-SERIAL CH340 (COMn) Properties" dialogs will close.
  13. Disconnect the USB cable of the Arduino board from your computer.
  14. Reconnect the USB cable of the Arduino board to your computer.
  15. Wait for the "USB-SERIAL CH340 (COMn)" device to appear under the "Ports (COM & LPT)" section of the Device Manager tree.
    :red_exclamation_mark: This will take a couple of minutes as Windows must first automatically reinstall the driver.
    :red_exclamation_mark: It might appear first as a "USB2.0-Serial" device under the "Other devices section of the tree. Just wait for a little longer and it will appear in its final place under the "Ports (COM & LPT)" section.
  16. Click the following link to download the previous version of the driver from an archive of the chip manufacturer's website:
    https://web.archive.org/web/20220519153932/https://www.wch-ic.com/downloads/file/65.html
  17. Wait for the download to finish.
  18. Run the downloaded CH341SER.EXE file.
  19. A "User Account Control" dialog may now appear asking "Do you want to allow this app to make changes to your device?". Click the "Yes" button.
  20. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  21. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  22. Click the "OK" button in the "Driver install success!" dialog.
    The dialog will close.
  23. Click the X icon at the top right of the "DriverSetup(X64)" dialog.
    The dialog will close.
  24. Switch back to the Windows "Device Manager".
  25. Double click on the "USB-SERIAL CH340 (COMn)" device under the "Ports (COM & LPT)" section.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  26. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  27. Click the "Update driver" button.
    An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
  28. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
  29. You should now see the driver installation wizard update the driver. Wait for the update to finish, as indicated by the message "Windows has successfully updated your drivers" in the dialog.
  30. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
    The dialog will close.
  31. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  32. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  33. Click the "Yes" button.
    The "Driver Package rollback" dialog will close.
  34. Click the "Close" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.

Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error before. Hopefully this time everything will work as expected.

I CAN CLICK IT

OK, great. Then go right ahead and follow the instructions I provided in my previous reply.

. Variables and constants in RAM (global, static), used 28780 / 80192 bytes (35%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1504 initialized variables
╠══ RODATA 1196 constants
╚══ BSS 26080 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60375 / 65536 bytes (92%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 27607 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 271040 / 1048576 bytes (25%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 271040 code in flash
esptool.py v3.0
Serial port COM3
Connecting...

A fatal esptool.py error occurred: Write timeout

I'm not sure, but I think it is progress at least. This means the upload process got past the phase where it previously failed with that "A fatal esptool.py error occurred: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)" error. Unfortunately it then failed at the following step.

It might well be that the failure you are encountering now is completely unrelated to the cause of the failure you encountered previously. When undertaking complex technical endeavors as we often do in our Arduino projects, it is common to end up in a situation where the system has multiple distinct problems. This means that solving one problem only advances you to encountering the next problem in the stack. That makes it difficult to see that any progress is being made, but with enough perseverance you can solve all the problems and finally reach a fully functional state.

That said, I would recommend requesting a refund of the board from the seller you purchased it from. The boards with the unlabeled "CH340" chips are very low quality. Unless you absolutely have no alternative, or you just get masochistic enjoyment through tackling annoying technical challenges, it is really not worth wasting a lot of time trying to get garbage hardware like this working.

Buy a board from a reputable seller and you'll be able to have more fun progressing with your project instead of fighting to try to get garbage hardware to do even the most basic things.

I like your suggestion but i can't buy a new one for it, If you or anyone know to solve please.

I am not seeing this only as a project , Problem solving. If someone know's to solve this i will learn the solutions for the problem's will be in hereafter.

You are already a step further but I would like to highlight the following.

From the opening post

  1. Serial port COM8
  2. A device attached to the system is not functioning

From post 4

  1. Serial port COM3
  2. Access is denied

Those are not the same ports and errors.

It was resoleved now the problem is different