Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
The arduino will start executing immediately, unless you have serial statements looking for a connection holding up execution. can you share your code? – sspence65 yesterday
    
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 yesterday
    
Actually the message is sent repeatedly but the arduino will probably reset a second time when the virtual serial port is opened. – Chris Stratton yesterday
    
@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 empty – vcapra1 yesterday
    
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 yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.