Hello, I am new to Arduino and I've stuck myself with a problem that I can't resolve on my own.
I am using a code i found on this forum to test a cable for continuity, short or open but I need to modify it to include two more wires. My issue is that the two wires I am adding are splices and each has 3 ends. So for 1 wire I will be needing 3 pins to test it. My issue is when i try to do something it either passes the test even when i disconnect one of the wires, or it is showing short when the connections are good. Can you help me modify the code? You assign the pins as you please.
Thanks a lot in advance.
// 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, };
const byte pinsCableEnd[] = {11,12,13,A0 };
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
}
}
With the increasing use of ChatGPT, I t'ink it's time to withdraw. It's hard enough reading a noob's mind, let alone a noob advised by artificial insemination.
I'm done.
You think about how this feature should work (using ideas, expressions, not program code). Come back here with a good description of how the test should be performed, and then people might help you with the coding part.
At the moment, you are asking us to research, design, and also implement it. You should do some of the work yourself.
Wow, I just needed help making 3 pins test connectivity between them, didn't think i't would be such a big deal for you. Some of you seemed really offended by the use of ChatGPT, well I'm not a programmer, I did not know what to do and I asked a thing that would not be mad at me for asking. Sorry for bothering you guys