Hello, I am making a cable tester using the arduino mega. the cable is only around 1m but it has 58 pins. this meant that regular testing possibilities like attaching beginning pin and end pin of the cable to separate pins on the arduino board was not feasible as i would need 116 pins that way. the cable tester will test continuity of each pin and if there are any shorts between pins.
after some research i found a way. If i create a dummy plug with diodes for one of the cable then i could connect only one end of the cable to the arduino and use only 58 pins. The dummy plug is connected in the following way:
lead lead diode
1 2 A to K
2 3 K to A
3 4 A to K
4 5 K to A
5 6 A to K
etc...
I have an uncertainty when trying to program this cable tester. If for example I set pin 3 as pinMode(ouput) then pin 2 and 4 should be set as pinMode(input) or as pinMode(input_pullup)?
The reason i have this issue is that in a previous post (Continuity Tester (Pass or Fail outcome only) - Project Guidance - Arduino Forum #7) someone wrote some code for a cable tester and the pins were set as pinMode(input_pullup) but if i understand correctly the way input_pullup mode works that wouldn't test that pin 2 and 4 at all.
Below i attached my code so far. I am aware that pin 1 will have a different code as it is asymmetrical compared to the other odd pins but i just wanted to keep it simple for now i can just add some if statements later.
enum {PASS, FAIL_NOTCONNECTED, FAIL_WRONGCONNECTED, FAIL_SHORTENED };
//setting all pin numbers to cable pins
const byte pins[]= {1, 2, 3, 4, 5, 6, 7, 8,9 ,10};
const byte NUMCABLES=sizeof(pins);
void setup() {
Serial.begin(9600);
Serial.println("################################################");
Serial.println("# CABLE TESTER #");
Serial.println("################################################");
}
void allPinsInputHigh()
{ // set all pins to INPUT_PULLUP in a for-loop
for (byte i=1;i<NUMCABLES;i++)
{
pinMode(pins[i],INPUT_PULLUP);
}
}
void DoOneTest()
{
byte result;
Serial.println();
Serial.println("### TEST ###");
for (byte i=1;i<NUMCABLES;i++) // test each pin
{
result= PASS; // initially there is no error found, assume PASS
allPinsInputHigh();
if(i&0x01)
{
// first test is for continuity and OUTPUT/HIGH for odd pins
pinMode(pins[i], OUTPUT);
if (digitalRead(pins[i-1])!=HIGH)
{
bitSet(result,FAIL_NOTCONNECTED);
}
if (digitalRead(pins[i+1])!=HIGH)
{
bitSet(result,FAIL_NOTCONNECTED);
}
// then check for continuity and OUTPUT/LOW
digitalWrite(pins[i], LOW);
if (digitalRead(pins[i-1])!=LOW)
{
bitSet(result,FAIL_NOTCONNECTED);
}
if (digitalRead(pins[i+1])!=LOW)
{
bitSet(result,FAIL_NOTCONNECTED);
}
}
// final test for short circuit against other pins. different tests for odd or even
for (byte j=1;j<NUMCABLES;j++)
{
allPinsInputHigh();
pinMode(pins[i], OUTPUT);
//even pins
if ((i&0x00) && (j!=i) && (digitalRead(pins[j])==HIGH))
{
bitSet(result, FAIL_SHORTENED);
}
//odd pins
if ((i&0x01) && (j!=i) && (digitalRead(pins[j])==HIGH) && (j-i!=1) && (j-i!=-1))
{
bitSet(result, FAIL_SHORTENED);
}
}
Serial.print("Line ");
Serial.print(i);
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
}
}