Testing for crosswires

So I have code that tests a cable harness. Here it is below:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x27,16,2); 

//Arrays to set which pins are outputs and which are inputs:
int outPin[] = {2, 3, 4, 5, 6, 7, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
int inPin[]  = {8, 9, 10, 11, 12, 50, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 53};
int pin_size = 20;
int loop_count = 0;
int voltage;

void setup() {
    lcd.init(); 
    lcd.backlight(); 

    //initialize the digital pin as an output or input:
    pinMode((int)outPin, OUTPUT);
    pinMode((int)inPin, INPUT);

    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0,0);
    lcd.print("Welcome to my");

    lcd.setCursor(0,1);
    lcd.print("Cable Tester!");
    delay(3000);
    lcd.clear();
      
}

void loop() {   

    // Send the outputs.
    digitalWrite(outPin[loop_count], HIGH);  
    delay(100);              
    digitalWrite(outPin[loop_count], LOW);    
    delay(100);              

    // Receive the inputs:
    voltage = digitalRead(inPin[loop_count]);
    
    lcd.print ("Cable " + String(inPin[loop_count]) + ": ");

    // LCD prints PASS or FAIL status using a switch statement:
    switch (voltage){

        case HIGH:
            lcd.print("PASS");
            break;

        case LOW:
            lcd.print("FAIL");
            break;

        default:
            lcd.print("UNKNOWN");
    }
    
    // Delay and increment the loop counter for the next set of pins.
    delay(1000);
    loop_count++;
    lcd.clear();

        // Check if reached the end of all pins.
    if (loop_count == pin_size){
        lcd.print ("Reached end!");
        delay(1000);
        lcd.clear();
        lcd.print("Testing again...");
        delay(1000);
        lcd.clear();
        loop_count = 0;
    }
}

My circuit is simple. I'm using an Arduino mega board, with the cables connected directly to the digital I/O pins and LCD using an I2C bus.

I'm close to being finished but I am struggling to include code that'll check for crossed wires. I know to assign 2 pins per cable like:

int j = 20; 
  int CABLE_A[] = {2, 8};
  int CABLE_B[] = {3, 9};

But I'm unsure if there is anything else I must add. Any pointers?

Thank you.

please include the schematics. We have no idea how it's wired.

1 Like

The logic in your sketch is a bit mixed up. You send the output high, then low, then check just one input, which will always be low.

I think you need to check all the inputs every time you send an output high, so you'll be able to spot crossed wires etc.

Something like this:

  1. Make the first output high
  2. Loop through all the inputs to see which are connected to the output.
  3. Print the result (or save it so you can report at the end) - is the connection OK, or mis-wired (how), or unconnected?
  4. Make the first output low
  5. Make the second output high
  6. Loop through the inputs as before
  7. Print the results (or save them)
    and so on

The best way is probably a pair of nested for loops.

As you've not included a circuit diagram I'm only guessing but I suspect you've not considered the need for pull up or down resistors. If a wire you are testing is open circuit and there are no resistors then the corresponding input will be any old voltage and might test high or low.

My apologies for getting back late.

Here's my circuit design:


(I didn't draw the input wires connecting because it would get messy and they're labelled so it is obvious where they are going; directly to the connector)

And here's a picture of the actual circuit:

It works fine testing the cables, displaying PASS or FAIL on the LCD.

Does it work? Just looking quickly, I don't understand this bit:

   digitalWrite(outPin[loop_count], HIGH);  
    delay(100);              
    digitalWrite(outPin[loop_count], LOW);    
    delay(100);

It looks like the output is turned low before the checks are performed...

I have a buddy that wants me to design one for about 50 pins... I don't want to do the soldering. :slight_smile:

Here's a video of it working

I change wires around and it works fine so I'm unsure what could be wrong with the code.

I do see your point on that piece of code though, the digitalwrite LOW should be after it is checked, yes?

I'm fed up after soldering just 10 wires so I couldn't imagine doing a 50 pin cable tester haha.

I would suggest a different approach such that you never have 2 push-pull outputs active at one time, i.e. an active High signal fighting an active Low signal. Write the code so that there is one active LOW and many Passive HIGHs (from the internal pullup resistors).

In setup(), make all pins INPUT_PULLUP

In loop(),
Make 1 pin an OUTPUT, and drive it low.
Check all the inputs at the other end to see that only 1 is low, and it is the correct pin. That way you check for continuity, miswiring, and that there are no shorts.
If you do get a mismatch, you have to ask yourself if there is a miswiring at send side or at the receive side?

Make the the output an input again.

Update loop_count, and repeat for the next pin.

For a 50-pin cable, using some shift registers would be required as the none of the Arduino processors have 100 IO.
I think 84 or 86 tops if you had a fully broken out Atmega2560 board.

I would do it the same way tho - use a part like TPIC6C595, which is Open Drain, to drive one line low and look for only one input low - the right one, and no shorts to other pins.

Bob has a good solution but it could work both ways. The input impedance of the arduino is high enough that you can sense voltage on multiple faults.

We used to use various terminations and light up cable checkers in the military. I hate those cables and connectors. I have a buddy who checks the systems on the Lockheed Martin optical surveillance equipment. Sometimes I get to play with them.

He can make his own tester... LOL... he's just being lazy. I would be happy to help if he did the soldering. Some of those cables get complicated and do not always have a 1-1 arrangement. In some ways a light-up tester that sends voltage and lights LED's for continuity might be easier. That way you can just keep notes on what should be connected. Some wires can have intentional "Y" connections.