Need help with codes (continuity cable tester with lcd 16x2 i2C)

It works. Is there a way to change from 4 to 12 wires? I tried adding 12 but got error, the result is not the same.

int endA[sizeTest] = {4, 5, 6, 7,8,9,10,11,12,13,14}; //pins end A
int endB[sizeTest] = {22,23,24,25,26,27,28,29,30,31,32,33}; //pins endB

It doesn't work like 4 wires. The results showing xxxxxxxxx11
Instead of 0000000000011
The X should be only when wire is shorted.

It looks like this part of the code inside runText_4x1() has been hardcoded to 4 pins instead of using sizeTest

Hi, thanks for replying, I also tried to change runText_12x1() and J < 12;
still error results xxxxxxxxxxx instead of 000000000000

It looks like your counter array also depends on sizeTest == 4 since it does this comparison at the end of the scan

    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }

but since you are looping 12 times, counter will be 11 if the pin is open, not 3

OMG! That was so simple! All I need just to change the Counter & #define sizeTest xx
You're the Best! I really Appreciate all everyone been helping me. Here's my final code, it a bit bothers me with the delay looping flicker on LCD display results.

//pins 

#define sizeTest 12 

int endA[sizeTest] = {22,24,26,28,30,32,34,36,38,40,42,44}; //pins end A
int endB[sizeTest] = {23,25,27,29,31,33,35,37,39,41,43,45}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2; 

//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail; 

void setup() { 

Serial.begin(115200); //serial used for debugging only
lcd.begin(20, 4); 

//setup pins
for (int i = 0; i < sizeTest; i++) {
pinMode(endA[i], OUTPUT);//set output pins (end A)
pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
}
pinMode(pSwitch, INPUT_PULLUP);
//lcd.clear();
//lcd.setCursor(0, 1);
//lcd.print("Cable Tester");
//lcd.print("Press Enc p/ Start");
} 

void loop() {
//run the test
runTest_4x1();
delay(1000);
} 

void runTest_4x1() { 

// add space for null terminator
char s[sizeTest+1] = "0000"; 

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Checking 12 Pin...");
lcd.setCursor(0, 1); 

// re-initialize reqired variables
fail = false;
for (int i = 0; i < sizeTest; i++){
result[i] = -1;
test[i] = -1;
counter[i] = -1;
} 

for (int i = 0; i < sizeTest; i++) {
counter[i] = 0;
for (int j = 0; j < 4; j++) {
digitalWrite(endA[i], LOW); //set all outputs to LOW
}
for (int j = 0; j < sizeTest; j++) { //check for crossed / open circuits vs closed, good, circuits
digitalWrite(endA[j], HIGH); //scan across the inputs in turn
test[i] = digitalRead(endB[i]); //read the output
if (test[i] == 1 && j != i) { //crossed or open circuit
counter[i]++;
result[i] = 8 + j;
}
else if (test[i] == 1 && j == i && result[i] < 8 ) { //Good, closed circuit
result[i] = 0;
}
digitalWrite(endA[j], LOW);
//debugging
/*
  Serial.print("test input core  ");
        Serial.print(i);
        Serial.print(" with output core  ");
        Serial.print(j);
        Serial.print(" test =");
        Serial.print(test[i]);
        Serial.print(" counter =");
        Serial.println(counter[i]);
      */
    }
    Serial.print("Core ");
    Serial.print(i);
    Serial.print(" result = ");
    if (result[i] == 0) {
      Serial.println(" 1");
      s[i] = '1';
    }
    else if (counter[i] == **11) { //change sizetest value #define above)**
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2); 

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 3);
  //lcd.print("Press to Start");
}

But you didn't change those things. Others on the forum did.

Maybe that is why the original code waited for a button press? Every 1000ms, you clear the screen and reprint the results, over and over and over...

Yes, i had to change delay 1000 or higher to avoid flickering on LCD because i like it detects cable in real time when plug/unplug without using switch.

I was thinking if is possible i can run multiple codes for 12 wires, 8 wires...
I did some research in the forum about call function(1) (2). Very interesting!

Right now i have 2 types of cable to test (8 & 12 cond) and i am wasting 2x Arduino Mega for each... i am still learning

Btw, as you can see (photo) my results display 000000000000 (12 digits).
Is it possible to show on display:
123456789101112 for each wire?
Like, RJ45 tester (without shift register)

Example:
123456
12X564

Thanks


Note:
0 = open
1 = close
X = short

yes, it is possible. What have you tried? Post your best effort and people will help you.

No i have not tried. But i am thinking about it. I am also trying to make a pullup switch between 4 wires, 8 wires, 12 wires in the same sketch