Serial.print to Display 16x2 i2c

Can someone help me put serial to display on LCD 16x2 i2c please. Thanks

int sideA[] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44};
int sideB[] = {23, 25, 25, 27, 29, 31, 33, 35, 37, 41, 43, 45};

void setup()
{

  Serial.begin(115200);
  Serial.println("Starting.....");
  for (int i = 0; i < sizeof(sideA)/sizeof(sideA[0]); i++)
  {
    pinMode(sideA[i], OUTPUT);
    pinMode(sideB[i], INPUT);
  }

  Serial.println("Testing...");
  delay(2000);

  for (int i = 0; i < sizeof(sideA)/sizeof(sideA[0]); i++)
  {
    digitalWrite(sideA[i], HIGH);
    delay(5);
    int pin_status = digitalRead(sideB[i]);
    if (pin_status == HIGH)
    {
      Serial.println(" PASS");
      Serial.print("\t");
      Serial.print("PIN ");
      Serial.print(sideA[i]);
      Serial.print(", to PIN ");
      Serial.println(sideB[i]);
    }
    else
    {
      Serial.println (" FAIL");
      Serial.print("\t");
      Serial.print("PIN ");
      Serial.print(sideA[i]);
      Serial.print(", to PIN ");
      Serial.println(sideB[i]);
    }
    digitalWrite(sideA[i], LOW);
    delay(5);
  }
}

void loop() 
{

}

I have no idea how you might want the display to look so here is a simple "Hello World" sketch using an I2C enabled 16x2 LCD and the hd44780 library for I2C displays to get you started.
To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.
The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

Use the setCursor function to place items on the display.

// hd44780 library see https://github.com/duinoWitchery/hd44780
// thehd44780 library is available through the IDE library manager
#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
   lcd.begin(LCD_COLS, LCD_ROWS);
   lcd.clear();
   lcd.print("Hello World");
   lcd.setCursor(0, 1);
   lcd.print("Millis ");
}

void loop()
{
   updateLCD();
}

void updateLCD()
{
   static unsigned long lcdTimer = 0;
   unsigned long lcdInterval = 500;
   if (millis() - lcdTimer >= lcdInterval)
   {
      lcdTimer = millis();
      lcd.setCursor(8, 1);
      lcd.print("       "); // overwrite old data
      lcd.setCursor(8, 1);  // reset the cursor
      lcd.print(millis());
   }
}

I have the hd44780 library installed, but I have no idea what you're saying :slight_smile:
can you help me 1 time code so I can learn and see the differences in between serial and lcd?
Thanks

You need to be a bit clearer about what your problem is. What sort of display are you using?

There are lots of good tutorials on how to write to an LCD display.

Try https://www.arduino.cc/en/Tutorial/LibraryExamples/HelloWorld

I have LCD 16x2 i2C 4 wires (Vcc/Gnd/SDA/SLC)

Have a look at this... Google is your best friend.

I can see Hello World using HD44780, I don't know how to put the code to LCD from serial.print :frowning:

yes it is 0x27

Have you loaded the "Hello World" to your Arduino?

Does the display work? Does it show "Hello World" and count millis?

If so, play with the code to see what happens if you change the setCursor function or what is printed.

it does show on display, where do I start to keying the word from serial?

You need to explain better what you are tying to do.

Do you want to type characters on the Serial Monitor and have them display on the LCD?

My code works in Serial COM, but I like to display on the LCD

You print to the display the same as serial, you just have limited space to write to so you must plan what to write and when. Play with the example that I posted. Play with the examples that come with the hd44780 library, there are many. Look at the documentation that comes with the library, it is extensive.

I am not going to write the code for you, mostly because I have no idea what you want printed, where you want it printed or when you want it printed.

Yup... no idea either.

Basically, my code here works in serial monitor. I like this results to be displayed on LCD screen instead of serial display.

int sideA[] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44};
int sideB[] = {23, 25, 25, 27, 29, 31, 33, 35, 37, 41, 43, 45};

void setup() {
  Serial.begin(9600); //serial used for debugging only
  lcd.begin(16, 2);
}
  //setup Pin
  for (int i = 0; i < sizeof(sideA[]/sizeof(sideA[0]); i++)  {
    pinMode(sideA[i], OUTPUT);
    pinMode(sideB[i], INPUT);
  }
  lcd.clear();
  lcd.print("Cable Tester");
  lcd.setCursor(0, 1);
  lcd.print("Press to Start"); 
  {
    
  for (int i = 0; i < sizeof(sideA)/sizeof(sideA[0]); i++)  {
    digitalWrite(sideA[i], HIGH);
    int pin_status = digitalRead(sideB[i]);
    if (pin_status == HIGH)
    {

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Testing 4 pin");
  lcd.setCursor(0, 1);
  
      Serial.println(" PASS");
      Serial.print("\t");
      Serial.print("PIN ");
      Serial.print(sideA[i]);
      Serial.print(", to PIN ");
      Serial.println(sideB[i]);
    }
    else
    {
      Serial.println (" FAIL");
      Serial.print("\t");
      Serial.print("PIN ");
      Serial.print(sideA[i]);
      Serial.print(", to PIN ");
      Serial.println(sideB[i]);
    }
    digitalWrite(sideA[i], LOW);
    delay(5);
  }
}

void loop() 
{

}

You want the user to be able to scroll lines up and down to see all messages ?

That code will not compile. Look at the example that I posted. You must include the libraries and you must create an instance of the lcd. And you have a curly bracket that closes setup so that the rest of the code is hung outside of a function.

#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

And the [] after sideA in this line is in error.

for (int i = 0; i < sizeof(sideA[]/sizeof(sideA[0]); i++) 

@hoangv

You need to read the replies that people have provided - or they will stop replying to your posts.

No one here understands what you are trying to do.

I want the results display on LCD. That's all.
Sorry I am newbie and bad with coding

Did you read post #6? That tells you how to use an Ic2 LCD display.