Testing Pins from a probably damaged Arduino

I'm currently checking digital pins from an arduino MEGA2560 that was previously used with a RAMPS 1.4 as controller for 3D printer.

One limit switch was plugged with the wrong pins (short between 5V and Gnd) and sice then the LCD won't show correctly, only blanks characters one line and then totaly blank the other line.

The LCD works fine on an other arduino, so the problem isn't from this part.

I've made the following code to test the pins manually, one by one:

int inMin = 16;
int inMax = 53;
bool state = 0;

void setup() {

for (int i = inMin; i <= inMax; i++)
{
pinMode(i, INPUT);
}
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {

for (int i = inMin; i <= inMax; i++)
{
if (i == 20 || i == 21)
{

}

else
{
state = digitalRead(i);

if (state == HIGH)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
Serial.print("Ok - ");
Serial.print(i);
Serial.println();
}
}
}
}

I remarked that pins 17 act as 16, 27 as 26, 29 as 28. All others pins are fine.

Why would I read the wrong pins, dos this means that these digital pins are fried?

Try it again with     pinMode(i, INPUT_PULLUP);
and       if (state == LOW)
. The way you had it left all the input pins floating and subject to acting randomly. Ground each pin in turn and you SHOULD see that each pin only goes LOW when you ground it.

Thanks for the input. I think my code illustrate well my level on knowledge in electronics :slight_smile:

I have modified the RAMPS board and reassigned the 3 problematics pins to unused ones and it is now working wonderfully!