Hey,
I am after some help/guidance on two modifications i am looking to make on a cable tester i got working a little while back.
Basics of what this does is sets pins 2,3,4,5 & 6 to HIGH consecutively and then reads if they went HIGH from pins 7,8,9,10 & 11. Just a basic continuity test that works really well.
-
I currently i have a button that i press each time to test the cable and that is getting pretty boring keep pressing that every time to test each cable. I would like to put an auto sense feature, so for example if pins 2 & 7 are connected then run the test.... This may cause issues if the first pin of the cable i am testing is faulty but I cannot think of any other way to do this at the moment... Any ideas would be amazing.
-
Currently when i have run a test on a cable it will tell me if it has passed or failed, this works fine. But when I press the button to do another test it has the previous test result at the top of the LCD. I have tried to overcome this with the LCD clear but it just doesn't get rid go the text.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
String Line1;
String Line2;
uint8_t outPins[] = {2, 3, 4, 5, 6};// Output pins
uint8_t inpPins[] = {7, 8, 9, 10, 11};// Input pins
int run;
const int buttonPin = 12; // the number of the pushbutton pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
int buttonState = 0; // variable for reading the pushbutton status
int lastButtonState = 0;
// LCD SCROLLING SETUP //
void lcdPrint(String lcdText) {
lcd.clear();
Line1 = Line2;
lcd.setCursor(2, 0);
lcd.print(Line1);
Line2 = lcdText;
Line2.replace("\r\n", "");
lcd.setCursor(2, 1);
lcd.print(Line2);
Line1 = "";
lcdText = "";
}
// LCD SCROLLING SETUP //
void setup(){
Serial.begin(115200);
lcd.begin();
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Cable Tester");
delay(3000);
pinMode(buttonPin, INPUT);
}
void loop(){
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) { // reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
Serial.println("Button Press");
Serial.write(80);
lcd.clear();
delay(1000);
testTheCable();
}
}
}
lastButtonState = reading;
}
void testTheCable() {
lcd.clear();
for (uint8_t i = 0; i < sizeof(outPins); i++){ // Setup output pins
pinMode(outPins[i],OUTPUT);
digitalWrite(i,LOW);
}
for (uint8_t i = 0; i < sizeof(inpPins); i++){ // Setup input pins
pinMode(inpPins[i],INPUT); // Turn off internap pullup resistor
}
Serial.println("Begin...");
if (testCable() == true)
{
lcdPrint("** Passed **");
Serial.println("** Passed **");
}
else
{
Serial.println("** Failed **");
lcdPrint("** Failed **");
}
}
bool testCable(){
lcd.clear();
bool testResult = true; // Assume cable is good
uint8_t count = 0; // Count of correct connections
if (sizeof(outPins) != sizeof(inpPins)) { // Array sizes match?
Serial.println(F("ERROR: Array Sizes Do Not Match."));
return false; // Exit now
}
for (uint8_t o = 0; o < sizeof(outPins); o++){ // Loop though output pins
Serial.print("Pin \t");
Serial.print(o);
digitalWrite(outPins[o],HIGH); // Set pin high
if (digitalRead(inpPins[o]) == HIGH){ // Is correct pin connected?
count++; // Increment count
Serial.print("->"); // Display it as first pin
Serial.print(o); // Display it as first pin
int a = (o);
String myStr;
myStr=String(a);
lcdPrint(myStr + " -> " + myStr);
delay(500);
}
for (uint8_t i = 0; i < sizeof(inpPins); i++){// Scan input pins
if (digitalRead(inpPins[i]) == HIGH){ // If pin is high must be connected to output
if (o != i){ // If array numbers don't match then must be error
Serial.print(" X ");
Serial.print(i);
testResult = false;
int a = (o);
String myStr;// Bad wire
int b = (i);
String myStr2;
myStr=String(a);
myStr2=String(b);
lcdPrint(myStr + " X " + myStr2);
delay(500);
}
}
}
digitalWrite(outPins[o],LOW); // Set output back to low
Serial.println(); // New line ready for next pin
}
if (count != sizeof(outPins)){ // Have we had the correct number of correct pins?
testResult = false; // If not then must be error
}
return testResult;
}