ESP8266 Wemos D1 R2 PermissionError 13 when uploading

Hello everyone,
I have made an wifi controlled car I’m having trouble uploading code to my Wemos D1 R2 (ESP8266). Every time I try, Arduino IDE shows this error:
"ESP8266 Wemos D1 R2 PermissionError 13 when uploading
A fatal esptool.py error occurred: Cannot configure port, something went wrong.
Original message: PermissionError(13, 'A device attached to the system is not functioning.', None, 31)
Serial port COM8"

Details:

  • Board: Wemos D1 R2 & mini
  • Chip: ESP8266 (WiFi 802.11 b/g/n)
  • USB-to-Serial: CH340
  • Arduino IDE version: 2.2.1
  • OS: Windows 10 64-bit
  • USB cable: Branded data cable (not USB-C)
  • COM ports tested: COM8 (system-assigned), previously tried COM14

What I’ve tried so far:

  1. Installed the latest CH340 driver from WCH website
  2. Closed Serial Monitor and any other programs using COM ports
  3. Tried multiple USB ports (front and rear)
  4. Manual reset during upload
  5. Verified in Device Manager β†’ Wemos appears on COM8
    Even though Arduino IDE sometimes says β€œDone uploading”, the error still appears and the car does not respond.
  • What is causing this PermissionError 13?
  • How can I upload my code successfully to the Wemos?

My code

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

// ---------- Wi-Fi Hotspot ----------
const char* ssid = "MyCar";
const char* 
// ---------- Motor Pins (adjust if needed) ----------
#define M1A D1
#define M1B D2
#define M2A D3
#define M2B D4
#define M3A D5
#define M3B D6
#define M4A D7
#define M4B D8

ESP8266WebServer server(80);

// ---------- HTML Web Page ----------
const char htmlPage[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>WiFi Car Control</title>
  <style>
    body {font-family: Arial; text-align:center; margin-top:40px;}
    button {width:120px; height:60px; font-size:20px; margin:6px; border-radius:10px;}
  </style>
</head>
<body>
  <h2>πŸš— WiFi Car Controller</h2>
  <button onclick="fetch('/forward')">Forward</button><br>
  <button onclick="fetch('/left')">Left</button>
  <button onclick="fetch('/stop')">Stop</button>
  <button onclick="fetch('/right')">Right</button><br>
  <button onclick="fetch('/backward')">Backward</button>
</body>
</html>
)rawliteral";

// ---------- Motor Control ----------
void stopMotors() {
  digitalWrite(M1A, LOW); digitalWrite(M1B, LOW);
  digitalWrite(M2A, LOW); digitalWrite(M2B, LOW);
  digitalWrite(M3A, LOW); digitalWrite(M3B, LOW);
  digitalWrite(M4A, LOW); digitalWrite(M4B, LOW);
  delay(5);
}

void forward() {
  digitalWrite(M1A, HIGH); digitalWrite(M1B, LOW);
  digitalWrite(M2A, HIGH); digitalWrite(M2B, LOW);
  digitalWrite(M3A, HIGH); digitalWrite(M3B, LOW);
  digitalWrite(M4A, HIGH); digitalWrite(M4B, LOW);
  delay(10);
}

void backward() {
  digitalWrite(M1A, LOW); digitalWrite(M1B, HIGH);
  digitalWrite(M2A, LOW); digitalWrite(M2B, HIGH);
  digitalWrite(M3A, LOW); digitalWrite(M3B, HIGH);
  digitalWrite(M4A, LOW); digitalWrite(M4B, HIGH);
  delay(10);
}

void left() {
  digitalWrite(M1A, LOW); digitalWrite(M1B, HIGH);
  digitalWrite(M2A, HIGH); digitalWrite(M2B, LOW);
  digitalWrite(M3A, LOW); digitalWrite(M3B, HIGH);
  digitalWrite(M4A, HIGH); digitalWrite(M4B, LOW);
  delay(10);
}

void right() {
  digitalWrite(M1A, HIGH); digitalWrite(M1B, LOW);
  digitalWrite(M2A, LOW); digitalWrite(M2B, HIGH);
  digitalWrite(M3A, HIGH); digitalWrite(M3B, LOW);
  digitalWrite(M4A, LOW); digitalWrite(M4B, HIGH);
  delay(10);
}

// ---------- Setup ----------
void setup() {
  Serial.begin(115200);
  Serial.println("\nStarting WiFi Car Controller...");

  // Motor pins
  int pins[] = {M1A, M1B, M2A, M2B, M3A, M3B, M4A, M4B};
  for (int i = 0; i < 8; i++) pinMode(pins[i], OUTPUT);
  stopMotors();

  // Start Access Point
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);
  Serial.print("Access Point: "); Serial.println(ssid);
  Serial.print("IP Address: "); Serial.println(WiFi.softAPIP());

  // Web routes
  server.on("/", []() { server.send(200, "text/html", htmlPage); });
  server.on("/forward", []() { forward(); server.send(200, "text/plain", "Moving Forward"); });
  server.on("/backward", []() { backward(); server.send(200, "text/plain", "Moving Backward"); });
  server.on("/left", []() { left(); server.send(200, "text/plain", "Turning Left"); });
  server.on("/right", []() { right(); server.send(200, "text/plain", "Turning Right"); });
  server.on("/stop", []() { stopMotors(); server.send(200, "text/plain", "Stopped"); });

  server.begin();
  Serial.println("Web server started.");
}

// ---------- Main Loop ----------
void loop() {
  server.handleClient();
  yield(); // prevent WDT resets
}

The above looks like a message from Windows device manager; I might be wrong though.

What does Windows device manager think of your board? Any yellow triangles?

Anything connected to your board? More than likely in which case a schematic / wiring diagram might be useful.

If yes, disconnect it all and try again.

No i have not seen anything such yellow triangles i have tried many possibilities

. 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

A fatal esptool.py error occurred: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)

So your COM port and error have now changed?

No, The error what i've told

image



You need to determine what a Windows PermissionError 13 is and how to fix it. Google is your friend.

Hi @rbk_123. Please tell us which USB to serial bridge chip your Arduino board has. This is a black chip near the USB socket.

The chip will usually be identified by writing on the top. This might say something like "WCH CH340G" or "SILABS CP2102".

Examples:

WCH CH340

πŸ“·

SparkFun - CC BY-SA 4.0 (cropped)

There are some boards on the market that have a USB chip with the same IC package as the WCH CH340, and which are identified by the computer as a CH340. However, these chips don't have the "WCH CH340C ..." labeling like you see on the chip in the picture above:

πŸ“·

NodeMCU Lua Lol1n V3.jpg by Popolon - CC BY-SA 4.0 (cropped)

These mysterious unlabeled chips have different characteristics than the labeled CH340 chips, so please let us know if yours is labeled or not.

Silicon Labs CP2102

CP2102

πŸ“·

SparkFun - CC BY-SA 4.0 (cropped)

Not labeled it's plain black

This error occurs when uploading to the boards that use specific batches of the WCH CH340 USB chip. The problem only occurs when using the latest version of the CH340 Windows driver.

The workaround for the problem is to perform a "roll back" to an older version of the driver that is compatible with these problematic "CH340" chips. I'll provide instructions you can follow to do that:

  1. 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
  2. Wait for the download to finish.
  3. Run the downloaded CH341SER.EXE file.
  4. 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.
  5. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  6. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  7. Click the "OK" button in the "Driver install success!" dialog.
    The dialog will close.
  8. Click the X icon at the top right of the "DriverSetup(X64)" dialog
    The dialog will close.
  9. Close Arduino IDE if it is running.
  10. Connect the Arduino board to your computer with a USB cable.
  11. Open the Windows Device Manager.
  12. Select View > Devices by type from the Device Manager menus.
  13. Open the "View" menu.
  14. If there is a βœ“ to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  15. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  16. 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.
  17. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  18. You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
    1. Click the "Update driver" button.
      An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
    2. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
    3. 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.
      :red_exclamation_mark: It is possible you will instead see the message "The best drivers are already installed". If so, please stop following the instructions here and reply on this forum topic to let us know. I'll provide alternative instructions you can follow.
    4. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
      The dialog will close.
  19. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  20. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  21. Click the "Yes" button.
    The "Driver Package rollback" dialog will close.
  22. 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.

Chatgpt can't able to resolve my problem my last choise was arduino forum

Till this step it's all fine. After it is not installing driver by itself this screen appears.

  1. Click the following link to download the previous version of the driver from an archive of the chip manufacturer's website:
    Wayback Machine
  2. Wait for the download to finish.
  3. Run the downloaded CH341SER.EXE file.
  4. 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.
  5. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  6. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  7. Click the "OK" button in the "Driver install success!" dialog.
    The dialog will close.
  8. Click the X icon at the top right of the "DriverSetup(X64)" dialog
    The dialog will close.
  9. Close Arduino IDE if it is running.
  10. Connect the Arduino board to your computer with a USB cable.
  11. Open the Windows Device Manager.
  12. Select View > Devices by type from the Device Manager menus.
  13. Open the "View" menu.
  14. If there is a βœ“ to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  15. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  16. 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.
  17. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  18. You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
  19. Click the "Update driver" button.
    An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
  20. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.

ChatGPT is a 2yo. Post 13 has your solution.

I can't see βœ“ to the left of the "Show hidden devices " menu item

Just a wild guess here, are you an admin user or non-admin?

admin.

Ok, then just continue ignoring step 14