27
votes

I've uploaded a sketch to an Arduino Uno whose loop is something like this:

void loop(){
    Serial.println("Hello, World!");
}

So, now, I can't upload anything anymore, because the IDE says "port already in use".

Is there a way to "reset" the Arduino without another programmer?

Nothing else is using the serial port, and everything went just fine until I uploaded the previous sketch.

I've found some interesting things:

21
Do you have the Ardunio "Serial Monitor" window open? If so, that will block you from communicating with the board.spring

21 Answers

29
votes

Try the following:

  1. Prepare the basic empty program (empty setup, loop, etc.)
  2. Compile it.
  3. Reset the Arduino using the hardware button on the chip
  4. Press Ctrl + U to upload your code.
  5. If unsuccessful - got to 3.

There is a delay before the boot loader starts the programs, just work on your timing. It worked for me when a bug in my Arduino's code was executing a soft reset every 500 ms.

5
votes

I had the same problem on two Arduinos (one Uno, and one Modern Device Freeduino/USB Host board) and the window between reset and the beginning of serial port usage was so small that it was impossible to upload.

I finally fixed the problem by purchasing another Arduino Uno and building an ISP cable per these instructions, and using it to flash the Bare Bones app from the examples into each inaccessible board, using Arduino IDE version 0023, following these instructions to change preferences.txt. (Be sure to save the original file before editing it so you can replace it after you've rescued your Arduino.)

It took one quick upload to fix each board. Such a fast fix after so much grief. You might not want to purchase another Arduino, but consider these benefits:

  • You can overwrite the bootloader on your Arduino to gain more space.
  • Once the bootloader is overwritten, the board will boot faster.
  • Supposedly you can program raw AVRs for special projects, but I have not tried this: Google for ArduinoISP
  • It will quickly fix Arduinos that you block in the future.
  • You can now safely experiment to find ways to prevent serial port usage from locking up the device in the future.
4
votes

Arduino Leonardo board:

  1. Unplug the USB cable
  2. Connect the RX Pin to ground
  3. Plug in the USB cable
  4. Upload a new program
  5. Remove the USB cable
  6. Remove the RX grounding
3
votes

Make sure you plug the Arduino directly into the computer and not through a hub. Using a hub will give you this error.

3
votes

After scratching my head about this problem, here is a very simple solution that works anytime:

  • Unplug your USB cable
  • Go in Device Manager
  • Click on Ports (COM & LPT)
  • Right click on Arduino....(COMx)
  • Properties
  • Port Settings
  • Put Flow Control to HARDWARE
  • Create an empty sketch (Optional)
  • Connect the USB cable
  • Upload (Ctrl + U)

// Empty sketch to fix the upload problem
// Created by Eric Phenix
// Nov 2014

void setup()
{
}

// The loop routine runs over and over again forever:
void loop()
{
    delay(1000);
}

Et voila!

1
votes

Here's what I did in Linux to be able to program my Arduino Micro which was stuck in a loop sending the 0 key when connected by USB;

# while true; do xinput float $(xinput --list | grep -i Arduino | awk '{print $7}' | cut -d'=' -f 2); done

Your output might be slightly different so just try running;

# watch xinput --list

then plug in the Arduino and see how the output is formatted.

This stopped X from accepting the keypresses and allowed the Arduino IDE to program finally!

1
votes

Based on my experience with the communication already in use or blocked, I would say that the program you are interfacing with still has the communication open.

I also found that if you disconnect the USB cable it will rest the communication. It is not the greatest solution, but it solves the problem.

1
votes

For Arduino Yún users, try uploading via Ethernet/Wi-Fi (menu ToolsPort).

I had exactly the same problem, and I tried pretty much everything (apart from burning a new bootloader). I am surprised it worked, but I've uploaded an empty sketch without any problem.

1
votes

I just spent the last five hours searching for a solution to this problem (serial port COM3 already in use and grayed out serial port)...I tried everything every forum and Q&A site I could find suggested, including this one...

What finally fixed it (got rid of the last code I'd input that got stuck and uploaded simple blink function)?

Follow this link -- http://arduino.cc/en/guide/windows and follow the instructions for installing the drivers. My driver was "already up to date", but following these steps fixed the glitch. I am now a happy camper once again.

Note: Resetting the board manually with the button on the chip, or digitally through miscellaneous codes on the Internet did not work to fix this problem, because the signal was somehow blocked/confused between my Arduino Uno and the port in my laptop. Updating the drivers is like a reset for the "serial port already in use" problem.

At least so far...

1
votes

I had this issue as well. I tried the above methods and none seemed to work, however something that did work (somehow, not sure if it was just a freak thing or it is actually a way to do it) was:

  1. Unplug USB from the Arduino
  2. Press and hold the reset button
  3. Plug in USB and power up
  4. Continue holding and upload the sketch. Once it's done uploading, release the reset button.
1
votes

I had the very same problem today. Here is a simple solution we found to solve this issue (thanks to Anghiara):

Instead of loading your new code to the Arduino using the "upload button" (the circle with the green arrow) in your screen, use your mouse to click "Sketch" and then "Upload".

Please remember to add a delay() line to your code when working with Serial.println() and loops. I learned my lesson the hard way.

0
votes

If you still have the serial console open, it will reserve the serial port. Close it, and try again.

0
votes

Be sure you are not accessing the serial port from a terminal. That loop (or any code) should not prevent the Arduino from being programmed.

0
votes

I got a similar problem.

If I power on my Arduino, there is a delay before the uploaded program execute.

So I use that delay for uploading new program, or empty program:

void setup(){}

void loop(){}

So my problem was solved.

Unplug any connection to Arduino pins before upload.

0
votes

If the port says Already used, then you are probably using the wrong port.

Switch it to the port where you connected your Arduino and then try to re-upload, you will definitely see it work.

0
votes

If nothing helped then you should arrange one more board and try to flash it through the Arduino as ISP option as shown in Arduino as ISP and Arduino Bootloaders or From Arduino to a Microcontroller on a Breadboard.

Instead of a boot loader, you can select your own programs to flash via ISP.

0
votes

The only way it worked for me for arduino nano 33 iot is via pressing the reset button on the board continuously many time then press uoplad!

-1
votes
  1. Unplug Tx from the microcontroller
  2. Insert USB cable
  3. Wait until full load
  4. Connect Rx with hardware
  5. Compile empty sketch in prosses and unconnect tx (don't worry about the error)
  6. Connect Rx with hardware
  7. Compile empty sketch
  8. Power off and connect Tx
-1
votes

I also had your problem,and I solved the problem using the following steps (though you may already finish the problem, it just shares for anyone who visit this page):

  1. Unplug your Arduino
  2. Prepare an empty setup and empty loop program
  3. Write a comment symbol '//' at the end of program
  4. Set your keyboard pointer next to the '//'symbol
  5. Plug your Arduino into the computer, wait until the Arduino is completely bootloaded and it will output 'Hello, World!'
  6. You will see the 'Hello, World!' outputting script will be shown as comment, so you can click Upload safely.
-2
votes

Here is the best way that works out if you are trying to program through the USB cable:

  1. Ground the Tx signal on the board (connect digital I/O #1 to GND)
  2. Plug the USB cable
  3. Upload a new program
  4. Remove the USB cable
  5. Remove Tx grounding

You are all set!

-2
votes
  1. First of all, connect your Arduino device.
  2. Then go to Device Manager and uninstall the driver.
  3. Now remove your Arduino device.
  4. Again connect you Arduino device to your system.
  5. Now install your driver (which you have uninstalled earlier).

It will free your port for sure.