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:
This question is related to
serial-port
arduino
reset
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!
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.
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!
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...
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.
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.
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.
Arduino Leonardo board:
Try the following:
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.
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:
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:
It will free your port for sure.
After scratching my head about this problem, here is a very simple solution that works anytime:
// 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!
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):
For Arduino Yún users, try uploading via Ethernet/Wi-Fi (menu Tools → Port).
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.
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.
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.
Here is the best way that works out if you are trying to program through the USB cable:
You are all set!
If you still have the serial console open, it will reserve the serial port. Close it, and try again.
Make sure you plug the Arduino directly into the computer and not through a hub. Using a hub will give you this error.
Source: Stackoverflow.com