Tuesday, February 23, 2016

Using Arduino to Test Network Cables.

Using 2 network connectors that normally snap into wall plates and accept network cables I built a network cable tester using an Arduino Pro Mini, a breadboard, a couple of inches of network cable and 8 1M Ohm resistors. The code I used is at the end of the page.  And off course, if you wire things differently, your pinout order might have to change.

I wired up one of the network cable connectors to just turn the data around.  I looked at A mode and just hooked green up to green white, orange up to orange white, blue up to blue white, and brown up to brown white.  The two punch downs on the side closest to where the wire connects just loop around, and the two on the back side connect strait across.

The other end I wired up to the A mode as well, using a 3 inch piece of network cable.  I followed the same color code on this side, the A mode, and matched the color of the cable to the little block of color on the side of the connector to the color of the wire.  I stripped the ends of the wires and pushed them into the breadboard so they lined up with pins 2 through 9.

Then I connected one end of a cable to the turn around plug and the other end into the connector attached to the Arduino.  At this point I thought I was pretty much done.  So I wrote the program and immediately just began to get random data from the pins.  Seems that if they are set to input they will float and hold a voltage like a capacitor for many minutes after they had been charged up. And even waving your hand near them is enough to make them read high. So I had to add 8 high value resistors from each pin to ground to bleed off this voltage, and the once nice and neat breadboard looks very messy.  What I need is a high value resistor pack that will just plug in to all those pins and to ground. This allowed excess voltage to bleed off over about 10 milliseconds time and let me read the voltage correctly.

The code was pretty strait forward.  I just needed to set all the pins into input mode and then one at a time set a pin to output mode HIGH and then read all the other pins to make sure I get a voltage on one and only one pin, and that it is the correct pin.   Then set that pin back to LOW and make it an input again, and select the next pin and do the same thing.  If everything is good, light an LED green.

The Arduino is able to easily perform these checks 4 times a second, giving me the opportunity to move the cables around and see of there are any intermittent contacts on either end or breaks in the wire.

I found the correct pin order by reading a known good cable.  It was an A cable, then I read a B cable and it returned the exact same pin order.  So I thought that a cross over cable must be different, but it returned the exact same pin order as A and B modes.  So that made that easy. Still don't understand why a cross over cable works the same as A and B. I tested it on several cables to make sure the cables I had were correct.

The code is as follows:


//Uncomment the following line to see output on the serial terminal.
//#define SERIALDEBUG 1

int good[8]= { 3, 2, 5, 4, 7, 6, 9, 8};

void setup() {                
#ifdef SERIALDEBUG
  Serial.begin(115200);
  //Serial.println("Checking pins.");
#endif
  
  // initialize the digital pin as an output.
  pinMode(12, OUTPUT);
}

void loop() {
  
  int x, y, z;
  // Set all the pins low.
  for (x=2; x<10; x++) {
    digitalWrite(x, LOW); 
    pinMode     (x, INPUT);
  }
  
  z=0;
  // Go through each pin, one at a time.
  // find where pin was routed to
  for (x=2; x<10; x++) {
    
    // setup current pin
    pinMode(x, OUTPUT);
    digitalWrite(x, HIGH); 
    delay(10); 

    // Find matching pin.
    for (y=2; y<10; y++) {

       if (x==y) continue;
       if (digitalRead(y) == HIGH) {
         if (good[x-2] == y)
            z++;
         else
            z+=100;
#ifdef SERIALDEBUG            
         Serial.print("good ");
         Serial.print(good[x-2]);
         Serial.print(" Z ");
         Serial.print(z);
         Serial.print(" Pin ");
         Serial.print(x);
         Serial.print(" is wired to pin ");
         Serial.println(y);
#endif
       }
    }
    
    // Set current pin back to the rest
    digitalWrite(x, LOW);
    pinMode     (x, INPUT);
  }
  
  if (z == 8)
      digitalWrite(12, HIGH);
  else
    digitalWrite(12, LOW);

#ifdef SERIALDEBUG
  Serial.println("");
  delay(1000);
#else
  delay(200);
#endif
}

No comments:

Post a Comment