Need help with codes (continuity cable tester with lcd 16x2 i2C)

Hi guys,
I am newbie and learning Arduino coding. I did a lot of research and found 1 closed thread 2 years ago, Sam was posting this code. I need help how to change LCD 20x4 to 16x2 i2C.

Thanks

(I did some translation from his original code to English)

//Circuit tester sketch for Arduino Mega (Uno)
//(c) Samuel Silva

//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is

// 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

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;

//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

Serial.begin(115200); //serial used for debugging only
lcd.begin(20, 4);

//setup pins
for (int i = 0; i < sizeTest; i++) {
pinMode(endA[i], OUTPUT);//set output pins (end A)
pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
}
pinMode(pSwitch, INPUT_PULLUP);
lcd.clear();
lcd.print("Cable Tester");
lcd.setCursor(0, 1);
lcd.print("Press Enc p/ Start");
}

void loop() {
//run the test
if (!digitalRead(pSwitch)) {
runTest_4x1();
delay(200);
}
}

void runTest_4x1() {

// add space for null terminator
char s[sizeTest+1] = "0000";

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Testing 4 Pin");
lcd.setCursor(0, 1);

// re-initialize reqired variables
fail = false;
for (int i = 0; i < sizeTest; i++){
result[i] = -1;
test[i] = -1;
counter[i] = -1;
}

for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
s[i] = '1';
}
else if (counter[i] == 3) {
Serial.println(" O");
s[i] = '0';
fail = true;
}
else {
Serial.println(" X");
s[i] = 'X';
fail = true;
}
}
lcd.print(s);
lcd.setCursor(0, 2);

if (fail) {
Serial.println("DEFECT");
lcd.print("DEFECT");
}
else {
Serial.println("CABLE OK");
lcd.print("CABLE OK");
}
Serial.println();
lcd.setCursor(0, 3);
lcd.print("Press Enc P/ Start");
}

Find an example of a simple “hello world” type sketch for an I2C LCD 16x2 display and get that working. Then compare the differences to the LCD parts of the cable tester sketch and start changing it to match.

Clearly, you have only lines 0 and 1 on the display and the lines are 4 characters shorter so you’ll have to make other adjustments.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

I replaced and try to reup sketch, gettin error.

LiquidCrystal_I2C lcd(I2C_ADDR,
En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin,
BACKLIGHT_PIN, POSITIVE);

I removed everything in this line still failed to define: lcd.print()
I got stuck here

Thanks.

Test

Please post the full sketch and the full error message

first error:

exit status 1
'POSITIVE' was not declared in this scope

then i remove it, got another error

exit status 1
'lcd' was not declared in this scope

Thanks

Hi, @hoangv
Can you post your existing code in the next post please?
Use code tags as described in the link in post#3.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi [@TomGeorge,
This thread was 2 years old back you were helping Sam on this sketch, I have a Mega with 16x2 i2c.
I want to try this code to see if it works.
Thanks
(sorry for edit this post)

//Circuit tester sketch for Arduino Mega (Uno)
//(c) Samuel Silva

//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is

// 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

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;


//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(20, 4);

  //setup pins
  for (int i = 0; i < sizeTest; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press Enc p/ Start");
}

void loop() {
  //run the test
  if (!digitalRead(pSwitch)) {
    runTest_4x1();
    delay(200);
  }
}

void runTest_4x1() {

  // add space for null terminator
  char s[sizeTest+1] = "0000";

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 Pin");
  lcd.setCursor(0, 1);

  // re-initialize reqired variables
  fail = false;
  for (int i = 0; i < sizeTest; i++){
    result[i] = -1;
    test[i] = -1;
    counter[i] = -1;
  }

  for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
      s[i] = '1';
    }
    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2);

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 3);
  lcd.print("Press Enc P/ Start");
}

Unfortunately, there are several LiquidCrystal_I2C libraries. The one that uses POSITIVE is the "NewLiquidCrystal_lib" GitHub - fmalpartida/New-LiquidCrystal: Clone of the new liquid crystal library from: https://bitbucket.org/fmalpartida/new-liquidcrystal

You can also switch over to the hd44780 library and adjust your code accordingly

I also have NewLiquidCrystal library installed, i don't know how to change the code from 20x4 to 16x2 i2c

Hi,

Change;

 lcd.begin(20, 4);

to;

 lcd.begin(16, 2);

Its in the setup() statement.

Tom.... :smiley: :+1: :coffee: :australia:

@TomGeorge
I am getting: Error compiling for board Arduino Mega or Mega 2560.

#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_I2C_ByVac.h>
#include <LiquidCrystal_SI2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR1W.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <SI2CIO.h>
#include <SoftI2CMaster.h>

LiquidCrystal_I2C lcd(0x27,16,2);

#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is

// 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

//pins

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;


//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(16, 2);

  //setup pins
  for (int i = 0; i < sizeTest; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press Enc p/ Start");
}

void loop() {
  //run the test
  if (!digitalRead(pSwitch)) {
    runTest_4x1();
    delay(200);
  }
}

void runTest_4x1() {

  // add space for null terminator
  char s[sizeTest+1] = "0000";

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 Pin");
  lcd.setCursor(0, 1);

  // re-initialize reqired variables
  fail = false;
  for (int i = 0; i < sizeTest; i++){
    result[i] = -1;
    test[i] = -1;
    counter[i] = -1;
  }

  for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
      s[i] = '1';
    }
    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2);

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 3);
  lcd.print("Press Enc P/ Start");
}

You do not need to include all those libraries. Look at the i2c Hello World example in the NewLiquidCrystal library and start there.

I can see my screen with example and I am able to upload sketch but no display.
Please see my new code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

//pins

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;


//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(16, 2);

  //setup pins
  for (int i = 0; i < sizeTest; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press Enc p/ Start");
}

void loop() {
  //run the test
  if (!digitalRead(pSwitch)) {
    runTest_4x1();
    delay(200);
  }
}

void runTest_4x1() {

  // add space for null terminator
  char s[sizeTest+1] = "0000";

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 Pin");
  lcd.setCursor(0, 1);

  // re-initialize reqired variables
  fail = false;
  for (int i = 0; i < sizeTest; i++){
    result[i] = -1;
    test[i] = -1;
    counter[i] = -1;
  }

  for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
      s[i] = '1';
    }
    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2);

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 3);
  lcd.print("Press Enc P/ Start");
}

Hi @TomGeorge
I play with the code, I got screen comes up but it stuck at "Cable Tester, Press Enc p/start" lcd.print. And when i remove lcd.print, i am stuck at lcd.print("Cable Tester"); on my display :slight_smile:
I just want to run this loop and test the wire automatically when i short 2 pins. Here's my new code using HD44780.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#include <hd44780.h>
const uint8_t i2cAddr = 0x27;
const int rs=0, rw=1, en=2, db4=4, db5=5, db6=6, db7=7, bl=3;
typeof(POSITIVE) blpol=POSITIVE; // backlight polarity level
LiquidCrystal_I2C lcd(i2cAddr, en, rw, rs, db4, db5, db6, db7, bl, blpol);
//pins

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;


//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(16, 2);

  //setup pins
  for (int i = 0; i < sizeTest; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press Enc p/ Start");
}

void loop() {
  //run the test
  if (!digitalRead(pSwitch)) {
    runTest_4x1();
    delay(200);
  }
}

void runTest_4x1() {

  // add space for null terminator
  char s[sizeTest+1] = "0000";

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 Pin");
  lcd.setCursor(0, 1);

  // re-initialize reqired variables
  fail = false;
  for (int i = 0; i < sizeTest; i++){
    result[i] = -1;
    test[i] = -1;
    counter[i] = -1;
  }

  for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
      s[i] = '1';
    }
    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2);

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 2);
  lcd.print("Press Enc P/ Start");
}

Thanks

I played around with the code, I finally got it working with button press analog pin A0 (A1,A2.e.g)
My working code with button press, pretty straight forward. However, I'd like to set it automatic scan instead of press the button, is there a way to change?

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
const uint8_t i2cAddr = 0x27;
const int rs=0, rw=1, en=2, db4=4, db5=5, db6=6, db7=7, bl=3;
typeof(POSITIVE) blpol=POSITIVE; // backlight polarity level
LiquidCrystal_I2C lcd(i2cAddr, en, rw, rs, db4, db5, db6, db7, bl, blpol);

//pins

#define sizeTest 4

int endA[sizeTest] = {4, 5, 6, 7}; //pins end A
int endB[sizeTest] = {8, 9, 10, 11}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;


//results
int result[sizeTest];
int test[sizeTest];
int counter[sizeTest];
bool fail;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(16, 2);

  //setup pins
  for (int i = 0; i < sizeTest; i++) {
    pinMode(endA[i], OUTPUT);//set output pins (end A)
    pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch, INPUT_PULLUP);
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press to Start");
}

void loop() {
  //run the test
  if (!digitalRead(pSwitch)) {
    runTest_4x1();
    delay(200);
  }
}

void runTest_4x1() {

  // add space for null terminator
  char s[sizeTest+1] = "0000";

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 Pin");
  lcd.setCursor(0, 1);

  // re-initialize reqired variables
  fail = false;
  for (int i = 0; i < sizeTest; i++){
    result[i] = -1;
    test[i] = -1;
    counter[i] = -1;
  }

  for (int i = 0; i < sizeTest; 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 < sizeTest; 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("test 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");
      s[i] = '1';
    }
    else if (counter[i] == 3) {
      Serial.println(" O");
      s[i] = '0';
      fail = true;
    }
    else {
      Serial.println(" X");
      s[i] = 'X';
      fail = true;
    }
  }
  lcd.print(s);
  lcd.setCursor(0, 2);

  if (fail) {
    Serial.println("DEFECT");
    lcd.print("DEFECT");
  }
  else {
    Serial.println("CABLE OK");
    lcd.print("CABLE OK");
  }
  Serial.println();
  lcd.setCursor(0, 3);
  lcd.print("Press to Start");
}

If you don't want to wait for a button press then remove the code in loop() that tests for a button press and only calls runText_4x1() if a button has pressed.

I am unable to upload sketch after "just" remove runText_4x1().
Btw, I can live with the button as of it's working now.
I tried to add more pin but it stop working, do I need to change anything in the setup beside this?

Thanks

#define sizeTest 12

int endA[sizeTest] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //pins end A
int endB[sizeTest] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}; //pins endB

Waits for button

void loop() {
  //run the test
    runTest_4x1();
    delay(200);
 }

Doesn't wait for button