digital INPUT PULL_UP ghost reading

I am using a Mega as a continuity tester to check a board for shorts by connecting test points to the digital pins on the Mega and sequencing through the pins, driving them low and checking which of the other pins are pulled low by this. For an example, to see if the test point connected to digital pin 2 is shorted to any other test points I set up all digital pins as pull-up inputs and set pin 2 as an output driven low. i then cycle through all the other pins and use digitalRead to look for other pins driven low. The problem I have been finding is that connecting one input to the low driven output will show two positive results, the pin that is connected and the pin immediately following it. That is to say if I connect pins 2 and 14 in the example above, the mega will detect that pins 14 and 15 are being driven low. This is the same regardless of which pins I use. Any thoughts on why? Here is my code:

int output = 2;
char buf[20];

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

void loop() {

for (int i=2; i<54; i++){
output = i;
pinMode(output, OUTPUT);
digitalWrite(output, LOW);

for (int j=2; j<54; j++){

if (j!=i){
pinMode(j, INPUT_PULLUP);
int val = digitalRead(j);

if (val<1){
sprintf(buf,“test pin: %d,%d, %d”, output, j, val);
Serial.println(buf);
}
}
}
}
}

Thanks for your help!

It would be nice you have a picture of your setup. Also, if you could mark your code it will show up in a nice code window. There is a </> symbol in the post tools bar. :slight_smile:

Without understanding completely what you are doing, one thing could be an issue. You set the pin to input pull-up up and immediately read it. Depending on the speed of your processor this can be very short. The build in pull up structures of most microcontrollers are fairly weak. So it takes a little while for the voltage to rise to high level even if the pins are open. If you have any other electronic components connected (they all have a capacitive component), this will take even longer.

This is probably a case where a delay is warranted. :slight_smile:

Thanks for the quick reply!

I didn't include a picture as there isn't really anything to show right now. I am using a jumper wire to simulate a short on a board so the only set up is that wire connecting two digital pins! I will try adding a small delay as per your suggestion!