How can I "reset" an Arduino board?
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:
- Problems with 0021 on Ubuntu 10.04 Lucid Lynx
- Re: Problems with 0021 on Ubuntu 10.04 Lucid Lynx
- Uno sending serial data becomes un-connectable to Serial Monitor
Try the following:
- Prepare the basic empty program (empty setup, loop, etc.)
- Compile it.
- Reset the Arduino using the hardware button on the chip
- Press Ctrl + U to upload your code.
- 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.
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.
Arduino Leonardo board:
- Unplug the USB cable
- Connect the RX Pin to ground
- Plug in the USB cable
- Upload a new program
- Remove the USB cable
- Remove the RX grounding
Make sure you plug the Arduino directly into the computer and not through a hub. Using a hub will give you this error.
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!
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!
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.
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.
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...
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:
- Unplug USB from the Arduino
- Press and hold the reset button
- Plug in USB and power up
- Continue holding and upload the sketch. Once it's done uploading, release the reset button.
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.
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.
- Unplug Tx from the microcontroller
- Insert USB cable
- Wait until full load
- Connect Rx with hardware
- Compile empty sketch in prosses and unconnect tx (don't worry about the error)
- Connect Rx with hardware
- Compile empty sketch
- Power off and connect Tx
If you still have the serial console open, it will reserve the serial port. Close it, and try again.
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.
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.
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.
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!
Here is the best way that works out if you are trying to program through the USB cable:
- Ground the Tx signal on the board (connect digital I/O #1 to GND)
- Plug the USB cable
- Upload a new program
- Remove the USB cable
- Remove Tx grounding
You are all set!
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):
- Unplug your Arduino
- Prepare an empty setup and empty loop program
- Write a comment symbol '//' at the end of program
- Set your keyboard pointer next to the '//'symbol
- Plug your Arduino into the computer, wait until the Arduino is completely bootloaded and it will output 'Hello, World!'
- You will see the 'Hello, World!' outputting script will be shown as comment, so you can click Upload safely.
- First of all, connect your Arduino device.
- Then go to Device Manager and uninstall the driver.
- Now remove your Arduino device.
- Again connect you Arduino device to your system.
- Now install your driver (which you have uninstalled earlier).
It will free your port for sure.
精彩评论