Hi there !
I'm making my first Arduino Uno project which to do a simple IDC 4 pin cable tester.
After reading some info on the internet, i found a good base to start and made a few modifications. I have changed the LCD and the number of pins and made some modifications on the code to suit my needs,
The program runs OK until it finds a faulty cable. Then, unfortunately, is not able to test it successfully again, only after a reset is able to test the cable correctly.
I'm comfortable with electronics but I'm not a programmer... so, something is missing here and i believe is when it starts the loop which is not reset the counters.
Many thanks.
Here's the code:
//Circuit tester sketch for Arduino Mega
//(c) Samuel Silva
// Many thanks to Tony since this project contains 95% of its code
//GPLv3
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is
// Address can be changed by soldering A0, A1, or A2
// Default is 0x27
// map the pin configuration of LCD backpack for the LiquidCristal class
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,
En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,
BACKLIGHT_PIN, POSITIVE);
//pins
int endA[4] = {4,5,6,7}; //pins end A
int endB[4] = {8,9,10,11}; //pins endB
int pSwitch=A0;
int pEncA= A1;
int pEncB= A2;
//results
int result[4] = {-1,-1,-1,-1};
int test[4] = {-1,-1,-1,-1};
int counter[4] = {-1,-1,-1,-1,};
bool fail =false;
void setup() {
Serial.begin(115200); //serial used for debugging only
lcd.begin(20, 4);
//setup pins
for(int i=0; i<4; i++){
pinMode(endA[i], OUTPUT);//set output pins (end A)
pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
}
pinMode(pSwitch,INPUT_PULLUP);
}
void loop() {
//run the test
runTest_4x1();
}
void runTest_4x1(){
String resultS="";
//user interface
lcd.clear();
lcd.print("Cable Tester: 4 Pins");
lcd.setCursor(0,1);
lcd.print("Press Enc to Start");
while(digitalRead(pSwitch))
{
delay(100);
}
delay(700); //debounce
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Testing: 4 pins");
lcd.setCursor(0,1);
for(int i=0; i<4; i++){
counter[i]=0;
for(int j=0; j<4; j++){
digitalWrite(endA[i], LOW); //set all outputs to LOW
}
for(int j=0; j<4; j++){ //check for crossed / open circuits vs closed, good, circuits
digitalWrite(endA[j], HIGH); //scan across the inputs in turn
test[i] = digitalRead(endB[i]); //read the output
if(test[i] == 1 && j!=i){ //crossed or open circuit
counter[i]++;
result[i] = 8+j;
}
else if(test[i] == 1 && j==i && result[i] <8 ){ //Good, closed circuit
result[i] = 0;
}
digitalWrite(endA[j],LOW);
//debugging
/*
Serial.print("test1 input core ");
Serial.print(i);
Serial.print(" with output core ");
Serial.print(j);
Serial.print(" test =");
Serial.print(test[i]);
Serial.print(" counter =");
Serial.println(counter[i]);*/
}
Serial.print("Core ");
Serial.print(i);
Serial.print(" result = ");
if(result[i] == 0){
Serial.println(" 1");
resultS+="1";
}
else if(counter[i] == 3){
Serial.println(" O");
resultS+="0";
fail=true;
}
else {
Serial.println(" X");
resultS+="X";
fail=true;
}
}
lcd.print(resultS);
lcd.setCursor(0,2);
if(fail){
Serial.println("FAILLED");
lcd.print("FAILLED");
}
else{
Serial.println("CABLE OK");
lcd.print("CABLE OK");
}
Serial.println();
lcd.setCursor(0,3);
lcd.print("Press Enc to Start");
while(digitalRead(pSwitch));
{
delay(100);
}
delay(700); //debounce
}