White boxes in first row of 16X2 LCD display

I am using an Arduino Mega 2560 board and a 16x2 LCD display. I have soldered the I2C module to the LCD display. I have run the I2C scanner code and it shows 0x27 which is what is already present. When I upload the "Hello World" example, the entire first row of LCD display shows white boxes. Need help with it as I am getting frustrated now.Processing: IMG_3093.HEIC...

Post clear photos showing the connection between the Mega and the LCD and the solder connections between the I2C backpack and LCD. To post a photo, just drag it into a reply window and drop it. The image in your original post does not show up.

The I2C pins on the Mega are pins 18 and 19 or the SDA and SCL pins by the pin13 and ground pins.

Have you tried the contrast adjustment?

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

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.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

Here is a simple Hello World sketch using the hd44780 library.

// 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());
   }
}

Thanks a lot! After uploading this code, the LCD display has started displaying the text.
Just have a look at this image. Thanks once again!
Here's the link to the image: IMG_3094.HEIC - Google Drive

@ansh_380, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Even though it appears to be working, I would recommend that you run the I2CexpDiag sketch to test everything.
It should be the first thing you run after installing the hd44780 library if you have an LCD with an i2c based backpack.

---- bill