Fixing Microcontroller Driver Error - Code 31

Posted on

by

in

Fixing Device Not Working in Windows/PC: Error Code 31 Troubleshooting Guide for your Arduino Microcontrollers

Introduction

Have you encountered an issue with your Microcontroller or any other electronic modules that have a specific driver like CH340, CP2102, or CH9102 when you plugged it into your USB and it does not work? You open your device manager, and you would see this specific error: “This device is not working properly because Windows cannot load the drivers required for this device. (Code 31). Object Name already exists.”

Object Name already exists error

Your device or modules get detected, but for some reason, it doesn’t work. If you are using a microcontroller like mine in this post, then you cannot upload any sketch to it. Let’s discuss how to fix this issue in this post.

Parts/Components Required

This project uses the following components:

ESP32 – Amazon | AliExpress

I am using an ESP32 with a CH340 USB driver in this post.

What causes Error Code 31?

As mentioned above, the first symptom you would notice is that your Arduino IDE or PlatformIO IDE could not detect your Microcontroller. If you open your Windows device manager, then you would see the exclamation mark on the Ports (COM &LPT) section.

I am using an ESP32 CH340 driver here, and the exclamation mark will tell you that something is wrong with the driver. The image below is both a good and a bad sign. The bad sign is that your ESP32 is confirmed to have a driver issue. On the other hand, the good sign is that your ESP32 is still working. If your ESP32 is not shown here, then your Microcontroller is probably defective or dead, unfortunately.

Device Manager Exclamation Mark Driver

Several things can trigger this issue:

  • Corrupted or outdated drivers
  • A Windows update that replaced a driver
  • Conflicting or duplicate drivers (“Object Name Already Exists”)
  • Removed or improperly installed hardware
  • Damaged system files

Most of the time, the driver is not loading correctly. You may encounter scenarios where you have already installed the correct driver and it is working fine, until the dreaded Windows Update automatically corrupts your driver.

So, how do you fix this error?

Possible Fixes to Error Code 31

There are lots of possible fixes that you would see on the internet, but for this post, I am focusing on what works when connecting your Arduino-based microcontrollers, like Arduino Uno, ESP8266, or ESP32, to your Windows laptop or computer.

Restart your computer

Restarting your computer should work and should fix this driver issue, but if the error still persists, then you can try the next suggestion.

Uninstall and Reinstall Device Driver

To uninstall and reinstall the device driver, follow the steps below.

Uninstall the Device driver from your system

  1. Right-click your device and click Uninstall device.
Object Name already exists error - Uninstall Device
  1. On the next pop-up, click Devices by Driver
Object Name already exists error - Devices by driver
  1. The next screen will show you the driver that is being used by your device. Click the main list. I am using a CH340 ESP32, and the driver that I installed initially is CH341. Just click the Remove driver
Object Name already exists error - Remove Device
  1. On the Remove Driver popup, make sure that the “Attempt to force removal of this driver while it is still in use by devices” option is selected, then click Remove.
Object Name already exists error - Remove Driver popup
  1. Verify that the driver was removed successfully.
Object Name already exists error - Verify Driver is Deleted

This will completely remove the device driver from your Windows/PC System. Next, we will try to reinstall the device driver for your microcontroller.

Reinstall the device driver

In this section, we will reinstall the device driver for your Microcontroller. I am using a CH340 USB driver for my ESP32, so I would need to install the said driver. If your microcontroller driver is different, you may need to look for a different driver.

How to Install the CH340/CH341 Driver?

You can open your browser and search for ‘WCH CH341SER.zip’, then click the first link. This will forward you to the original manufacturer of the CH340/CH341 driver.

Are CH340 and CH341 drivers different?

Both CH340 and CH341 are made by WCH (Nanjing Qinheng Microelectronics) (often just “WCH”). They are not identical, though they are related. Many boards use CH340 for USB-to-serial connectivity for microcontrollers (Arduino clones, etc.). Either way downloading CH341 works the same as CH340.

How to download CH340 CH341 driver

On the WCH site, just click the download button and wait for it to finish.

CH340 CH341 Manufacturer Driver Download

Unzip the downloaded file and click the SETUP.EXE

CH340 CH341 Setup FIles

Click the Install button and wait for the installation to finish.

CH340 CH341 Setup Install Popup

Verify that the driver is now properly installed

To verify if your issue is now fixed then open your Device Manager and in the Ports (COM and LPT) section, check if no exclamation mark is not present.

CH340 CH341 Driver Installed Successfully

If your device manager looks like the image above, then congratulations. You have now fixed the issue “This device is not working properly because Windows cannot load the drivers required for this device. (Code 31). Object Name already exists.”

Additional Questions

Will the above steps also work for non-microcontroller modules?

Yes, if you are using any other devices like USB to GSM modules, USB to RS-485 modules, or the like, then the steps above should work. Make sure to download the appropriate driver for your module.

Final Thoughts

In this post, we have discussed how you could troubleshoot the error “This device is not working properly because Windows cannot load the drivers required for this device. (Code 31). Object Name already exists.” in your Windows/PC System. If ever you ran across this particular issue then just follow the steps above to fix it.

I hope you learned something. Happy exploring!

Read Next:
Pico W -MicroPython MQTT – BMP/BME 280 Weather Station
Control DS18B20 using MicroPython with a Weather Station Project

If you like my post then please consider sharing this. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *