Arduino IDE isn’t able to load skethes to the arduino mega board

arduinobaudrate

I made a big mistake: I've written a small sketch just to play with my new arduino mega 2560. The sketch worked fine but a bit slow, so I thought that if I increase the baud-rate I will get faster communication to my computer. So I changed the baud-rate to 14400 (in the Serial.begin(); statement).

Now I'm not able to upload sketches any more, and I don't know how to solve this, I tried to burn the bootloader again but I don't know how to do it.

The sketch:

const int pin_in=A0;
const int cols=151;
int value;
int prev;

void setup() {
  Serial.begin(9600);
//  Serial.begin(14400);
}

void loop() {
  value=analogRead(pin_in);
  value=map(value,0,1023,0,cols);
  for (int i=0; i<cols; i++){
    if (i==value){
      if (value==prev){Serial.print("|");}
      else if(value<prev){Serial.print("/");}
      else if(value>prev){Serial.print("\\");}
    } else if (i%30==0){Serial.print("|");}
    else {Serial.print(" ");}
  }
  Serial.println("|");
  prev=value;
  delay(1);
}

When I try to upload my sketch (or any example sketch) I get error while opening /dev/ttyACMX although its present before trying to upload the sketch.

processing.app.SerialException: Error al obrir el port sèrie "/dev/ttyACM0".
    at processing.app.Serial.<init>(Serial.java:178)
    at processing.app.Serial.<init>(Serial.java:77)
    at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
    at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175)
    at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
    at processing.app.Sketch.upload(Sketch.java:1671)
    at processing.app.Sketch.exportApplet(Sketch.java:1627)
    at processing.app.Sketch.exportApplet(Sketch.java:1599)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
    at java.lang.Thread.run(Thread.java:744)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
    at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:213)
    at processing.app.Serial.<init>(Serial.java:163)
    ... 9 more
processing.app.debug.RunnerException: Error al obrir el port sèrie "/dev/ttyACM0".
    at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
    at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175)
    at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
    at processing.app.Sketch.upload(Sketch.java:1671)
    at processing.app.Sketch.exportApplet(Sketch.java:1627)
    at processing.app.Sketch.exportApplet(Sketch.java:1599)
    at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
    at java.lang.Thread.run(Thread.java:744)

Is there a way to reset an arduino mega 2560 board?

Best Answer

I'm Really sorry I wasted your time, I finally discovered it was a software bug, not hardware. trying the board on a different computer worked fine. trying a different board on my laptop made the same bug. When I uninstalled the IDE and re-installed it after that the problem remained. Finally I solved it deleting the preferences file, the hardware folder and the libraries folder (those which are on the sketchbook folder). Thank you anyway.