Something really crazy is going on with my Arduino [Inconsistent Code Outcomes]

Something really crazy is going on with my Arduino.

I have two computers: one is a laptop (running Vista SP1), the other a desktop (running Win7Pro SP1). I also have an Arduino Leonardo.

When I connect the Leonardo to the desktop and upload the following code, the code performs as it should: when the button is held down, the LED is lit; otherwise the LED is dark.

However, when I connect the Leonardo to the laptop, and load the exact same code, the LED remains lit constantly.

Both computers are running the same Arduino Software (Version 1.0.5-r2). Within the Arduino Software, the same Programmer (AVR ISP) is selected in both computers. In both computers, the Leonardo has the same driver (1.0.0.0 with a date of Jan 4 2013).

Here are the troubleshooting steps/scenarios I have tested:

Connecting the Leonardo to a different USB port on the laptop and reloading the code does not change the outcome. When the code is loaded, the LED remains lit.

If I connect the Leonardo to the desktop and upload the code, then disconnect the Leonardo and connect to the laptop, the code performs correctly.

If I connect the Leonardo to the laptop and upload the code, then disconnect the Leonardo and connect to the desktop, the code doesn't perform correctly (the LED remains lit).

While the obvious workaround is to load the code via the desktop and then plug the Leonardo into the laptop, it makes me wonder what other inconsistencies could arise with more complex Arduino code.

Does anyone have any suggestions as to what is going on, and how to fix the problem?

int Button1 = 5;
int GreenLED = 2;

void setup()
{
  pinMode(GreenLED, OUTPUT);
  pinMode(Button1, INPUT_PULLUP);
}

void loop()
{
  if(digitalRead(Button1) == LOW)
    {
      digitalWrite(GreenLED, HIGH);
    }
  if(digitalRead(Button1) == HIGH)
    {
      digitalWrite(GreenLED, LOW);
    }
}

...the LED...

Does this LED have a friend? A current-limiting resistor, perhaps?

int Button1 = 5;

Is the button actually connected to pin 5? Correctly connected?

The button resides on a breadboard and is connected to pin 5 with a jumper wire. The LED has a 1k resistor.

I've quadruple-checked the entire circuit. It is fine.

I am using the same exact circuit in both cases, I just plug the Arduino into either the laptop or desktop and upload the code.

Well, obviously the laptop is possessed :smiling_imp:
What happens if you load a simple "blink" code for pin 2 with the laptop? Or an empty code altogether? Does the LED stay on too?

Clear out the %TEMP% directory on both computers. Build the sketch on each computer. Locate then preserve the dot-hex file in the %TEMP% directory. Bring the two dot-hex files to the same location and compare them.

If they are not identical, you need to reinstall the Arduino software on both computers and try again.

If they are identical, I have no idea what you should do.

igendel:
What happens if you load a simple "blink" code for pin 2 with the laptop? Or an empty code altogether? Does the LED stay on too?

Igendel, when uploaded from the laptop, the "blink" code works correctly (onboard LED 13 blinks) as does a blank sketch (no leds are lit other than 'on').

Coding Badly, great idea! I will report back shortly.

Coding Badly, the .hex files were not identical. I will reinstall the Arduino software on both systems and update here as soon as possible.

Coding Badly, I reinstalled the Arduino software on both systems and uploaded the code from each computer.

The Arduino code now performs as it should in both computers, which is a relief, and the .hex files are also identical.

Thanks very much for your help in resolving this!

Do you have any idea what could have caused the problem in the first place?

No idea.

Thank you for the follow up. I'm glad to know you have it working.