G40PY:
The board is a Sintron Uno R3
Yes, R3 design is what you need for this application (or you could not use pin-13).
Here is the code for a cable tester with nine single lines to test:
// Cable Tester by "jurs" for Arduino forum
enum {PASS, FAIL_NOTCONNECTED, FAIL_WRONGCONNECTED, FAIL_SHORTENED };
// pin numbers for use at begin and end of cable
const byte pinsCableBegin[]= { 2, 3, 4, 5, 6, 7, 8, 9,10 };
const byte pinsCableEnd[] = {11,12,13,A0,A1,A2,A3,A4,A5 };
const byte NUMCABLES=sizeof(pinsCableBegin);
void setup() {
Serial.begin(9600);
if (sizeof(pinsCableBegin)!=sizeof(pinsCableEnd))
{
Serial.println("Wrong cable pin configuration!");
Serial.println("Fix declaration of pinsCableBegin[] and pinsCableEnd[] arrays!");
while(1); // error stop with endless loop
}
Serial.println();
Serial.println("################################################");
Serial.println("# CABLE TESTER #");
Serial.println("################################################");
Serial.println();
}
void allPinsInputHigh()
{ // set all pins to INPUT_PULLUP in a for-loop
for (byte i=0;i<NUMCABLES;i++)
{
pinMode(pinsCableBegin[i],INPUT_PULLUP);
pinMode(pinsCableEnd[i],INPUT_PULLUP);
}
}
void DoOneTest()
{
byte result;
Serial.println();
Serial.println("### TEST ###");
for (byte i=0;i<NUMCABLES;i++) // test each pin
{
result= PASS; // initially there is no error found, assume PASS
allPinsInputHigh();
// first test is for continuity and OUTPUT/HIGH
pinMode(pinsCableBegin[i], OUTPUT);
if (digitalRead(pinsCableEnd[i])!=HIGH)
{
bitSet(result,FAIL_NOTCONNECTED);
}
// then check for continuity and OUTPUT/LOW
digitalWrite(pinsCableBegin[i], LOW);
if (digitalRead(pinsCableEnd[i])!=LOW)
{
bitSet(result,FAIL_NOTCONNECTED);
}
// next test: check for wrong connections to other pins
for (byte j=0;j<NUMCABLES;j++)
{
if (j!=i && digitalRead(pinsCableEnd[j])==LOW)
{
bitSet(result, FAIL_WRONGCONNECTED);
}
}
// final test for short circuit against other pins
for (byte j=0;j<NUMCABLES;j++)
{
if (j!=i && digitalRead(pinsCableBegin[j])==LOW)
{
bitSet(result, FAIL_SHORTENED);
}
}
Serial.print("Line ");
Serial.print(i+1);
if (result== PASS) Serial.print(" PASS");
else Serial.print(" FAIL");
if (bitRead(result,FAIL_NOTCONNECTED)) Serial.print(" BREAK");
if (bitRead(result,FAIL_WRONGCONNECTED)) Serial.print(" WRONG");
if (bitRead(result,FAIL_SHORTENED)) Serial.print(" SHORT");
Serial.println();
}
Serial.println("Test finished.");
Serial.println();
}
void loop() {
if (Serial.available())
{
DoOneTest();
delay(20);
while (Serial.available()) Serial.read(); // clear Serial input buffer
}
}
Usage:
- compile and upload sketch to UNO R3 (or compatible R3) board
- connect all 9 pins at the begin of the cable to the pins declared in pinsCableBegin[]
- connect all 9 pins at the end of the cable to the pins declared in pinsCableEnd[]
- open the serial monitor and send something (at least one character)
(CR/LF would be enough, so you can send empty line if sending line ending is enabled)
Printed result shows PASS or FAIL with each line of the cable.
If it is FAIL, an additional hint (BREAK, WRONG, SHORT) is given which might be helpfui for repair
When using non-R3 boards, the board LED pin-13 cannot be used.
But with R3 design boards you can also use pin-13 without any problem.
How long are the cables you test? If the cables are very long (dozens or hundreds of meters), the sketch may show wrong results. For cables up to a couple of meters that code should work flawlessly.
What do you think?