Can't open device "\\.\COM2": The system cannot find the file specified.

I recently purchased a second-hand Due board (the mega-sized one) off a friend (it did previously work fine on his machines), and now I am unable to upload anything to it.

I have done nothing to it except plug some wires into it from a breadboard and plug it into the computer to upload code.

I have followed this admittedly simple diagram here:

and added an LED to pin 3, and tried to upload the code at the bottom of the post with the following settings:

  • Board: Arduino Duemilanove or Diecimila
  • Processor: ATmega328
  • Port: COM2
  • Programmer: AVRISP mkII (I didn’t change this one)

And yet I get the following error when I try to upload it:

avrdude: ser_open(): can't open device "\\.\COM2": The system cannot find the file specified.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

The code is verified and compiled so that isn’t an issue and I am plugged into the inner USB micro port (programming one).

Here is the code:

 const int buttonPin = 2;
const int ledPin = 3;

int buttonState = 0;

void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() 
{
  buttonState = digitalRead(buttonPin);

  if(buttonState == HIGH)
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

Any ideas or obvious signs I have done something wrong?

A Due and a Duemillanove are totally different boards.

To upload to a Due, you must install the official SAM board package through Tools -> Board Manager. That includes support for the Due, Zero, and other SAM-based boards.