Go Down

Topic: Arduino mega continuity and short tester (Read 906 times) previous topic - next topic

Paul_l

#15
Feb 10, 2018, 01:14 pm Last Edit: Feb 12, 2018, 07:44 am by Paul_l
Tom, if you will can you please help me to convert this code from serial monitor to lcd print and add a button to start the program instead of writing "Test" in serial monitor?

You can remove this
Code: [Select]

  Serial.println();
  Serial.println("################################################");
  Serial.println("#                CABLE TESTER                  #");
  Serial.println("################################################");
  Serial.println();

and add something to fit the 16x2LCD

Code: [Select]

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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22 };
const byte pinsCableEnd[]  = {23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 33, 34,35, 36, 37, 38, 29, 40, 41 };
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
  }
}




TomGeorge

Hi,
Do you have an LCD display?
Is it I2C or parallel interface?
What do you want displayed on the LCD.

You have the advantage of having monitor print scrolling down the screen and being able to see all you printout.
With the LCD you are limited to 2 rows of 16 characters, you can scroll with the LCD, but you will need to store  your printout in character arrays, or some shorthand.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Paul_l

Yes I have an LCD with I2C, on the LCD i want to display the test result like Test Pass or Test Fail, and if it is possible to be displayed on the second row the issue like this example Open at pin 10 or Short at pin 10.

I also attached 2 photos of my Mega and LCD with I2C adapter.

Thank you,
Paul Lungoci

Paul_l

#19
Feb 13, 2018, 01:16 pm Last Edit: Feb 13, 2018, 02:35 pm by Paul_l
I manage to make it work :)

Here is the final code :
Code: [Select]


#include <avr/wdt.h> //autoreset
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#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

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//pins
int ledPinPass = 52;
int ledPinFail = 12;
int endA[10] = {30,31,34,38,40,42,44,46}; //pins end A
int endB[10] = {32,33,35,39,41,43,45,47}; //pins endB
int pSwitch=53; //you can put here what you want pin X to gnd
int pEncA= 59;
int pEncB= 63;

//results
int result[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
int test[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
int counter[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
bool fail =false;

void setup() {

  MCUSR = 0;  // clear out any flags of prior resets.
  Serial.begin(115200); //serial used for debugging only
 lcd.begin (16,2); //  <<----- My LCD was 16x2

 
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
 
  //setup pins 
  for(int i=0; i<8; 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_5x2();
}

void runTest_5x2(){
  String resultS="";
  //user interface
  lcd.clear();
  lcd.print(" tester ");
 
  lcd.setCursor(0,1);
  lcd.print(" test1 ");
 
  while(digitalRead(pSwitch))
  {
    delay(100);
   
  }
  delay(500); //debounce
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Cablu sub testare");
  delay(500);
  //lcd.setCursor(0,1);
  for(int i=0; i<8; i++){
     counter[i]=0;
    for(int j=0; j<8; j++){
        digitalWrite(endA[i], LOW); //set all outputs to LOW
    }
    for(int j=0; j<10; 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] = 20+j;
        }
        else if(test[i] == 1 && j==i && result[i] <20 ){ //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]);
      */
   
    //old
    /*
     Serial.print("Core ");
    Serial.print(i);
    Serial.print(" result = ");
    if(result[i] == 0){
       Serial.println(" 1");
       resultS+="1";
    }
    else if(counter[i] == 9){
       Serial.println(" O");
       resultS+="0";
       fail=true;
    }
    else {
       Serial.println(" X");
       resultS+="X";
       fail=true;
    }
     */
         }
    //new
    delay(250); //delay between tests
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Testare grup= "); //group test
    lcd.print(i);
   // lcd.setCursor(0,1);
   // lcd.print("result =");
    if(result[i] == 0){
    lcd.print(" 1");
       resultS+="1";
    }
    else if(counter[i] == 9){
      lcd.setCursor(0,1);
       lcd.print("Open grup "); //open at group X
       lcd.print(i);
       delay(1000);
    //   lcd.setCursor(4,1);
       resultS+="0";
       fail=true;
     
    }
   
    else {
      lcd.setCursor(0,1);
       lcd.print("FireInvers/scurt"); //short or cross wire
       delay(1000);
       resultS+="X";
       fail=true;
       
    }
  }
 
  //lcd.print(resultS);
  lcd.setCursor(0,0);
 delay(1000);
 if(fail){
  lcd.clear();
   Serial.println("     FAILED");
   lcd.print(" Cablul defect");
   pinMode(ledPinFail, OUTPUT);
   digitalWrite(ledPinFail, HIGH);
 }
 else{
 
  lcd.clear();
   Serial.println("     PASSED");
   lcd.print("Cablul este bun");
   pinMode(ledPinPass, OUTPUT);
   digitalWrite(ledPinPass, HIGH);
   
 }
 Serial.println();
 lcd.setCursor(0,2);
 lcd.print(" Reset  automat");
  // while(digitalRead(pSwitch))
  {
    delay(300);
  }
  delay(700); //debounce
  //autoreset
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
for(;;) {

}
}



If anyone find some bugs or improves please do not be shy and post it here :)

larryd

No technical PMs.
The last thing you did is where you should start looking.

TomGeorge

#21
Feb 13, 2018, 10:25 pm Last Edit: Feb 13, 2018, 10:26 pm by TomGeorge
Hi,
Good stuff mate.. looks good..  :) :) :)


Tom. :)
Everything runs on smoke, let the smoke out, it stops running....

Paul_l

Congrats!

Thank you!

Hi,
Good stuff mate.. looks good..  :) :) :)

Tom. :)
Thank you!

I merge i think 3-4 cable tester codes and after aprox. 8 hours it is working like I wanted to:)

Thank you for your support!

Best regards,
Paul L.

Paul_l

Hello again :)

I am come up with an idea what if i can test each wire with a "probe" before I push a button and start the test. Yes I know why should I want a probe test if I have an automatic tester, the answer is why not :D

Here is my code, if anyone has an idea how can i make this work, please let me know :)

If you will scroll down in the code you will find the section where I want the probe to start workning
Quote
//Probe

/*
 * Here I want to add a probe
 * the probe is connected to the pin 7 of my mega
 * if anyone has any ideea how can I turn the probe low, all the B side HIGH
 * and display the result on my 16x2 lcd, it will help me alot
 */
 //Probe

Code: [Select]

#include <avr/wdt.h> //autoreset
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#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

int n = 1;
int data;
LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
//pins
//int probe = 8; //probe
int ledPinFail = 3;
int endA[19] = {13, 12, 14, 15, 17, 16, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; //pins end A
int endB[19] = {34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}; //pins endB
int pSwitch = 53;

//results
int result[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int test[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int counter[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
bool fail = false;

void setup() {

  MCUSR = 0;  // clear out any flags of prior resets.
  Serial.begin(115200); //serial used for debugging only
  lcd.begin (16, 2); //  <<----- My LCD was 16x2


  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home

  //setup pins
  for (int i = 0; i < 19; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
//  pinMode(probe[i], OUTPUT); //set probe output
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);

}

void loop() {


  //run the test
  runTest_19x2();
}

void runTest_19x2() {
  String resultS = "";

  //user interface

  lcd.clear();
  lcd.print(" TEXT ");
  lcd.setCursor(0, 1);
  lcd.print("  Text");
delay(1500);

  lcd.clear();
//Probe

/*
 * Here I want to add a probe
 * the probe is connected to the pin 7 of my mega
 * if anyone has any ideea how can I turn the probe low, all the B side HIGH
 * and display the result on my 16x2 lcd, it will help me alot
 */
 

//Probe

 
  while (digitalRead(pSwitch))
  {
    delay(100);

  }
  delay(500); //debounce
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Cablu sub testare"); //under test message
  delay(1000);

  for (int i = 0; i < 19; i++) {
    counter[i] = 0;
    for (int j = 0; j < 19; j++) {
      digitalWrite(endA[i], LOW); //set all outputs to LOW
     }
    for (int j = 0; j < 20; 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] = 38 + j;
      }
      else if (test[i] == 1 && j == i && result[i] < 38 ) { //Good, closed circuit
        result[i] = 0;
      }
      digitalWrite(endA[j], LOW);
    }

    delay(250); //delay intre teste
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Testare pin ");
    lcd.print(i + 1);
    if (result[i] == 0) {
      lcd.print("");
      resultS += "1";
    }
    else if (counter[i] == 19) {
      lcd.setCursor(0, 1);
      lcd.print("Open grup ");
      lcd.print(i + 1);
      delay(350);
      fail = true;

    }

    else {
      lcd.setCursor(0, 1);
      lcd.print("Short/Cross ");
      lcd.print(i + 1);
      delay(350);
      fail = true;
    }
  }
 
  lcd.setCursor(0, 0);
  delay(1000);
  if (fail) {
    lcd.clear();
    lcd.print(" Cablul defect"); //Brocken cable

    //buzzer
   
        pinMode(ledPinFail, OUTPUT);
        digitalWrite(ledPinFail, HIGH);
   
  }
  else {

    lcd.clear();
    lcd.print("Cablul este bun"); //OK cable

  }
  Serial.println();
  lcd.setCursor(0, 2);
  lcd.print(" Reset  automat");
  delay(700); //debounce
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
  for (;;) {

  }
}




MorganS

I see lots of delay()s and an unnecessary watchdog reset.

So how does the probing operation interact with the automatic operations? How do you intend to start or stop probe "mode"?

Instead of writing code, try to write the user manual. Think about how a person will control the tester. When you have got that part stable in your mind then you can write code which does that.
"The problem is in the code you didn't post."

Paul_l

Hello MorganS,

The probe mode will run continuously, it will be stopped when the start button (pSwitch = 53) will be pressed, after that the test will begin and after that the watchdog will reset the board to return to the probe mode.

The hole project started with a small continuity tester, then one of my friends come up with the "probe mode" idea, then i started thinking how can I make it possible.
The tester functionality is very basic you have a box with an LCD 16x2 a push button to start the tester and 2 connectors on the front side to connect the cable.

Also I attached 2 photos of the tester itself.


MorganS

Did you make any progress on the code?
"The problem is in the code you didn't post."

Paul_l

#28
Mar 16, 2018, 09:35 am Last Edit: Mar 16, 2018, 09:40 am by Paul_l
Hello everyone,

This is the final result, yes I know there are a lot of delays, but it`s working great.
Thank you for your support.

Keep up the good work!

This is my final code :

Code: [Select]

#include <avr/wdt.h> //autoreset
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#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

int n = 1;
int data;
LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
//pins
int probe = 8; //probe
int ledPinFail = 3;
int endA[19] = {13, 12, 14, 15, 17, 16, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; //pins end A
int endB[19] = {34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}; //pins endB
int pSwitch = 53;

//results
int result[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int test[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int counter[19] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
bool fail = false;
int nume = -1;  //local variable for probe
int nume2 = - 1; //local variable for probe
int mode = -1; // set the mode

void setup() {

  MCUSR = 0;  // clear out any flags of prior resets.
  Serial.begin(115200); //serial used for debugging only
  lcd.begin (16, 2); //  <<----- My LCD was 16x2


  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home

  //setup pins
  for (int i = 0; i < 19; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(probe, OUTPUT); //set probe output                 
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);

}

void loop() {


  //run the test
  runTest_19x2();
}

void runTest_19x2() {
  String resultS = "";

  //user interface

  lcd.clear();
  lcd.print(""); //main title
  lcd.setCursor(0, 1);
  lcd.print(""); //main2 title

  delay(1500);

  //Probe
  mode = 1;     
  while (mode == 1) {
    lcd.clear();
    lcd.print("   Probe mode"); //title
    lcd.setCursor(0, 1);
    lcd.print("Pin : ");
    lcd.setCursor(6, 1);
    for (int i = 0; i < 19; i++) {
      digitalWrite(endA[i], HIGH); //set all outputs to High
    }

    while (!digitalRead(probe) && digitalRead(pSwitch)) // verify if the probe or switch is pressed
    {
      delay(100);
    }
    if (digitalRead(pSwitch) == 0)  // if the button is pressed switch from probe mode to cable tester
    {
      mode = 0;
    }
    else {
      for (int i = 0; i < 19; i++) {
        digitalWrite(endA[i], LOW); //set all outputs to LOW
      }
      for (int i = 0; i < 19; i++) {
        digitalWrite(endA[i], HIGH); //set one by one the outputs on HIGH
        nume = digitalRead(probe); // flag
        if (nume == 1) {
          nume2 = i;    // the vector location of the probe on the specidic pin
        }
        digitalWrite(endA[i], LOW);
      }
     /* if (nume2 == -1) {     // fara
        // do nothing          // fara
      }                        // fara
      else {*/                // fara
        lcd.print(nume2 + 1); //connected pin
      // }
      pinMode(ledPinFail, OUTPUT);
      digitalWrite(ledPinFail, HIGH);
      delay(500);            // beep delay
      digitalWrite(ledPinFail, LOW);
      delay(1000);            // how much time to display the pin on the lcd
    }
  }

  //Probe

  delay(200); //debounce
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Cablu sub testare"); //under test message
  delay(750);

  for (int i = 0; i < 19; i++) {
    counter[i] = 0;
    for (int j = 0; j < 19; j++) {
      digitalWrite(endA[i], LOW); //set all outputs to LOW
    }
    for (int j = 0; j < 20; 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] = 38 + j;
      }
      else if (test[i] == 1 && j == i && result[i] < 38 ) { //Good, closed circuit
        result[i] = 0;
      }
      digitalWrite(endA[j], LOW);
    }

    delay(250); //delay intre teste
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Testare pin ");
    lcd.print(i + 1);
    if (result[i] == 0) {
      lcd.print("");
      resultS += "1";
    }
    else if (counter[i] == 19) {
      lcd.setCursor(0, 1);
      lcd.print("Open grup ");
      lcd.print(i + 1);
      delay(350);
      fail = true;

    }

    else {
      lcd.setCursor(0, 1);
      lcd.print("Short/Cross ");
      lcd.print(i + 1);
      delay(350);
      fail = true;
    }
  }

  lcd.setCursor(0, 0);
  delay(1000);
  if (fail) {
    lcd.clear();
    lcd.print(" Cablul defect"); //Fail cable

    //buzzer

    pinMode(ledPinFail, OUTPUT);
    digitalWrite(ledPinFail, HIGH);

  }
  else {

    lcd.clear();
    lcd.print("Cablul este bun"); //OK cable

  }
  Serial.println();
  lcd.setCursor(0, 2);
  lcd.print(" Reset  automat");
  delay(700); //debounce
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
  for (;;) {

  }
}


Go Up