I am having trouble with my Arduino Mega with getting the program to start when the Arduino is plugged into a computer via USB. All that happens is the LED turns on and stays on. The device does not initialize, and only when I press the reset button does it begin the setup. How can I make the Arduino start the program when it is first plugged into the computer?
EDIT: my code
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("test");
}
very simple, which is why i don't understand why this is happening
-
The arduino will start executing immediately, unless you have serial statements looking for a connection holding up execution. can you share your code?sspence65– sspence652016年08月16日 13:25:55 +00:00Commented Aug 16, 2016 at 13:25
-
As said by @sspence65, the Arduino starts as soon as you power it. You are simply missing the startup message because it is sent before you open the serial connection on the PC end.Edgar Bonet– Edgar Bonet2016年08月16日 14:47:10 +00:00Commented Aug 16, 2016 at 14:47
-
1Actually the message is sent repeatedly but the arduino will probably reset a second time when the virtual serial port is opened.Chris Stratton– Chris Stratton2016年08月16日 23:31:59 +00:00Commented Aug 16, 2016 at 23:31
-
@ChrisStratton, actually it doesn't reset and that is another problem I am having. For some reason when the connection is established, the Arduino does not reset and sometimes there is already data in the buffer and it confuses the program and often I have to restart the program one the buffer has been read emptyvcapra1– vcapra12016年08月17日 00:18:57 +00:00Commented Aug 17, 2016 at 0:18
-
Try explicitly toggling RTS and DTR via your computer's serial api. At some point you may need to look into details of the USB serial implementation on your specific "mega".Chris Stratton– Chris Stratton2016年08月17日 00:39:29 +00:00Commented Aug 17, 2016 at 0:39
1 Answer 1
I would recommend you to follow the following instructions step by step to verify your Arduino Mega.
- Reboot your computer
- Connect the Arduino using the USB cable to PC and check the Arduino itself if there is any jumper wires connected/grounded. If there are then remove them all.
- Upload a blank sketch first. Go to File -> New
- Verify the Arduino has accepted the blank sketch and resetted.
- Upload the Blink sketch from the File -> Examples -> 0.1Basics -> Blink
- Verify if the Pin 13/onboard LED is blinking. If yes then go to uploading your sketch, if no then there is a hardware/bootloader problem with your Arduino. Watch this video on how to burn bootloader here. https://www.youtube.com/watch?v=X5achE10rCI