Only white stripes on I2C 16x2 lcd display

Hello! I am pretty new to this stuff so I'm probably missing something pretty obvious, but I cant seem to make my lcd display show anything that I have coded it to.
Some pictures:


Code:


#include <Wire.h> // Set the LCD I2C address\
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
lcd.init();
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("joe mam");
lcd.setCursor(2,1):
lcd.print("ok no")

}
void loop()
{
  
}

I bought it and followed the tutorial from here https://www.amazon.co.uk/keyestudio-Display-Blue-Background-Backlight-Adjustable/dp/B01GKY5B2G/ref=cm_cr_arp_d_product_top?ie=UTF8

First off, turn down the contrast to the point where you just see the blocks.

Make sure 0x27 is the correct address.

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.

Adjust the contrast.

Hi @tishadev.
In the IDE examples you will find the sketch "i2c_scannr.ino".
Load and run it and see on the serial monitor if your backpack's address appears and if it's really 0x27.

RV - mineirin

Something to play with:

//Version 1.00

#include <Wire.h>

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Reference:       https://www.arduino.cc/en/Reference/LiquidCrystal

#include <hd44780.h>   //main hd44780 header

//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O expander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
//hd44780_I2Cexp lcd(0x3F);
hd44780_I2Cexp lcd(0x27);

const byte resetPin      = 8;
const byte bagPin        = 13;
const byte heartbeatLED  = 10;

unsigned int count;

byte last_resetPin;
byte last_bagPin;

//timing stuff
unsigned long heartbeatMillis;
unsigned long switchMillis;

//*******************************************************************************
void setup()
{
  //LED used to see if there is any code blocking
  pinMode(heartbeatLED, OUTPUT);

  // put your setup code here, to run once:
  pinMode (resetPin, INPUT_PULLUP);
  last_resetPin = digitalRead(resetPin);

  pinMode (bagPin,   INPUT_PULLUP);
  last_resetPin = digitalRead(bagPin);

  lcd.begin(16, 1);
  //                   111111
  //         0123456789012345
  //         COUNT =
  lcd.print("COUNT = ");

  //                   111111
  //         0123456789012345
  //         COUNT = 0
  lcd.print(count);

  lcd.noBlink();
  lcd.noCursor();

} //END of setup()

//*******************************************************************************
void loop()
{
  //***************************************
  //time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));

  }

  //***************************************
  //time to check the switches ?
  if (millis() - switchMillis >= 100)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();

  }

  //other none blocking code goes here

} //END of loop()

//*******************************************************************************
void checkSwitches()
{
  //***********************************************
  //bagPin switch
  byte currentState;

  currentState = digitalRead(bagPin);

  if (last_bagPin != currentState)
  {
    last_bagPin = currentState;

    if (currentState == LOW)
    {
      count++;

      //display the count on the LCD
      lcd.setCursor(8, 0);
      //clean out the old value
      //                   111111
      //         0123456789012345
      //         COUNT =  
      lcd.print("        ");

      lcd.setCursor(8, 0);
      //                   111111
      //         0123456789012345
      //         COUNT = xxxxxxxx
      lcd.print(count);

    }

  } //END of this switch


  //***********************************************
  //resetPin switch
  currentState = digitalRead(resetPin);

  if (last_resetPin != currentState)
  {
    last_resetPin = currentState;

    if (currentState == LOW)
    {
      count = 0;

      //display the count on the LCD
      lcd.setCursor(8, 0);
      //clean out the old value
      lcd.print("        ");

      //                   111111
      //         0123456789012345
      //         COUNT = 0
      lcd.setCursor(8, 0);
      lcd.print(count);

    }

  } //END of this switch

} //END of checkSwitches()

Hello and thanks for the quick response. I installed the library but I cant find the example your talking about, can you please send me the directory of it or the example itself? Thanks.

The hd44780 library comes with lots of documentation.
It is in the Documentation sketch.
It has clickable links in the comment at the top of the sketch.

--- bill

This example.

All of the examples on that last menu page should work with your display.

I think it is much easier to run the I2CexpDiag sketch that comes with the hd44780 library and it will test everything and printout information relating to any issues it finds.

--- bill

1 Like

I got these results when I ran the scanner

By the way, I am using an Arduino Leonardo board, if it matters.

I see that in the picture, now, it just didn't register. Looks so much like an Uno.

The I2C pins on a Leonardo are pins 2 and 3, not A4 and A5.

In the future, please copy and past the text not a screenshot.

Thanks so much! I would've never guessed that the problem was with the Arduino.

Notice that the boards (both the UNO and the Leonardo) have header pins specifically labeled SCL and SDA. If you use those, they will be connected to whatever pins are actually used for the I2C bus (good if you are making a shield you want to be multi-board compatible).

This output posted is is not from the I2C scanner.
The output is from the hd44780 library I2CexpDiag sketch.
Look at the output.
You can see that the SDA signal is on digital pin 2 and SCL is on digital pin 3 vs A4 and A5.
This is one of the values of using I2CexpDiag.
It shows you which pins to use.

--- bill