Mega 2560 pin 41 issue

I'm trying to make a wire harness tester and my mega freezes when pin 41 is connected to ground. No issues as far as I can tell with any other pins. Tried using a 1.2k resistor in case the internal pullup was shorted or something. I get the first "P" from my serial readout then garbage and it's frozen until I reset it. Running from USB laptop power with no shields or other devices attached.

#define Analog_Read_Port A0

int Pin_Number[40];
int Pin_ADC_Result[40];
int Short_Circuit_Detect = 0;
int sensorValue = 0;
bool Ground_Short = false;

void setup() {
  Serial.begin(9600);
  // while (!Serial.available());
  Serial.println(F("Serial available"));

  pinMode(Analog_Read_Port, OUTPUT);
  digitalWrite(Analog_Read_Port, LOW);

  Serial.println(F("Test probe intialized"));

  for (int IP1 = 2; IP1 <= 5; IP1++) {
    pinMode(IP1, INPUT_PULLUP);
  }

  for (int IP2 = 22; IP2 <= 47; IP2++) {
    pinMode(IP2, INPUT_PULLUP);
  }

}

void loop() {

  sensorValue = analogRead(Analog_Read_Port);
  delay(1);
  if (sensorValue != 0) {
    Serial.print(F("A0: "));
    Serial.println(sensorValue);
  }

  memset(Pin_Number, 0, 40);
  memset(Pin_ADC_Result, 0, 40);
  Short_Circuit_Detect = 0;

  for (int p = 2; p <= 5; p++) {
    if (digitalRead(p) == LOW) {
      Pin_Number[p] = 1;
      Short_Circuit_Detect++;
      Serial.print(F("Pin "));
      Serial.println(p);
      Serial.print(F(":"));
    }
  }

  for (int p = 22; p <= 47; p++) {
    if (digitalRead(p) == LOW) {
      Pin_Number[p] = 1;
      Short_Circuit_Detect++;
      Serial.print(F("Pin "));
      Serial.println(p);
    }
  }

  if (Short_Circuit_Detect > 1) {
    Serial.print(F("Short circuit detected across "));
    Serial.print(Short_Circuit_Detect);
    Serial.println(F(" pins"));
  }

}

this over flows the Pin_Number array which only has 40 elements, highest is at index 39..
re-think the logic a bit..

good luck.. ~q

Yep. Derped that one.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.