Hi,
I am new to Arduino and currently working on my first ever project which is a continuity tester with some other small functionality. The project will accommodate 10 different types of cables to test with some of them ranging up to 116 IO therefore I am using 8 MCP23017 E/SP to expand my IO requirements to cover this.
I am having trouble interfacing these chips with some existing code I found on another thread. I have attached the code below of which I am trying to replace the array elements in "pinsCableBegin" and "pinsCableEnd" with my own pin addresses for 1 of my 10 separate tests.
`
// 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
}
}
`
Specifically, I am unsure what syntax to use to call up a specific pin of one of the chips inside the array elements. For example, I have attached a schematic of one of the continuity tests (the simplest) below. I was wondering how I would declare 2 arrays for this test for the pins at either end of the cable as I'm unsure of how to address intended connections inside an array.
I have read about declaring each pin as an object then putting all the objects inside an array but I don't really understand any of the explanations around this or how to do it myself.
Any help with this would be greatly appreciated!
Thanks in advance.