// Cable Tester
// by Koepel, 26 feb 2023.
//
// Make the connections on the breadboard
//
// Warning: Do not use this as a cable tester.
// It might fail. I did not think this through.
// It should have at least 5 bugs.
//
// If you are looking for the Connection Scanner,
// then I'm afraid it is gone and overwritten by this.
// The sketch is still on the Arduino forum:
// https://forum.arduino.cc/t/sending-unique-simple-data-through-a-single-pin-to-be-read-by-another-pin-on-a-nano/1086151/27
#define NUM_WIRES 16
// Side A of the cable
const int pinsA[NUM_WIRES] = {37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22};
// Side B of the cable
const int pinsB[NUM_WIRES] = {39,38,41,40,43,42,45,44,47,46,49,48,51,50,53,52};
const int buttonPin = A8;
int old_buttonState = HIGH; // default HIGH, active LOW
void setup()
{
Serial.begin(115200);
Serial.println(F("Cable Tester"));
Serial.println(F("Press the button to test the cable"));
for( int i=0; i<NUM_WIRES; i++)
{
pinMode(pinsA[i], INPUT_PULLUP);
pinMode(pinsB[i], INPUT_PULLUP);
}
pinMode( buttonPin, INPUT_PULLUP);
}
void loop()
{
int buttonState = digitalRead( buttonPin);
if( buttonState != old_buttonState and buttonState == LOW)
{
// Scan and report at the same time.
// The result is not stored, only printed as text to the Serial Monitor
int error = 0;
for( int i=0; i<NUM_WIRES; i++)
{
digitalWrite( pinsA[i], LOW); // pre-set to low
pinMode( pinsA[i], OUTPUT);
delay(10); // it could be a long wire, let the signal settle
bool found = false;
for( int j=0; j<NUM_WIRES; j++)
{
// Scan connections from A side to A side
if( digitalRead(pinsA[j]) == LOW)
{
if( j != i) // not own wire ?
{
// shortcut to a wire on the B side
Serial.print( F("Wire A "));
Serial.print( i);
Serial.print( F(" is short circuit to wire A "));
Serial.print( j);
Serial.println();
error++;
}
}
// Check connection from A side to all the wires of the B side
if( digitalRead(pinsB[j]) == LOW)
{
if( j == i)
{
found = true;
}
else
{
// shortcut to a wire on the B side
Serial.print( F("Wire A "));
Serial.print( i);
Serial.print( F(" is short circuit to wire B "));
Serial.print( j);
Serial.println();
error++;
}
}
}
pinMode( pinsA[i], INPUT_PULLUP); // release this pin
if( !found)
{
Serial.print( F("Wire A "));
Serial.print( i);
Serial.print( F(" is not connected to wire B "));
Serial.print( i);
Serial.println();
error++;
// This wire did not reach the B side.
// Perhaps the wire from the B side connected to another wire from the B side ?
digitalWrite( pinsB[i], LOW); // pre-set to low
pinMode( pinsB[i], OUTPUT);
delay(10); // it could be a long wire, let the signal settle
for( int j=0; j<NUM_WIRES; j++)
{
// Scan connections from B side to B side
if( digitalRead(pinsB[j]) == LOW)
{
if( j!=i) // own pin
{
Serial.print( F("Wire B "));
Serial.print( i);
Serial.print( F(" is short circuit to wire B "));
Serial.print( j);
Serial.println();
error++;
}
}
}
pinMode( pinsB[i], INPUT_PULLUP); // release this pin
}
}
if( error == 0)
{
Serial.print( F("The cable has been tested and is okay"));
Serial.println();
}
}
old_buttonState = buttonState; // remember for next time
delay(20); // for debouncing of the button
}