LCD not printing in my sketch

I am using an i2c LCD with a backpack.
I have the backlight working but no data is being printed on the display.
could someone please look over this and suggest where I may have gone wrong

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

int DHpin = 8; // input/output pin
byte dat[5];

byte read_data()
  byte i = 0;
  byte result = 0;
  for (i = 0; i < 8; i++) {
    while (digitalRead(DHpin) == LOW); // wait 50us
    delayMicroseconds(30); //The duration of the high level is judged to determine whether the data is '0' or '1'
    if (digitalRead(DHpin) == HIGH)
      result |= (1 << (8 - i)); //High in the former, low in the post
    while (digitalRead(DHpin) == HIGH); //Data '1', waiting for the next bit of reception
  return result;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void start_test()
  digitalWrite(DHpin, LOW); //Pull down the bus to send the start signal
  delay(30); //The delay is greater than 18 ms so that DHT 11 can detect the start signal
  digitalWrite(DHpin, HIGH);
  delayMicroseconds(40); //Wait for DHT11 to respond
  pinMode(DHpin, INPUT);
  while (digitalRead(DHpin) == HIGH);
  delayMicroseconds(80); //The DHT11 responds by pulling the bus low for 80us;

  if (digitalRead(DHpin) == LOW)
    delayMicroseconds(80); //DHT11 pulled up after the bus 80us to start sending data;
  for (int i = 0; i < 5; i++) //Receiving temperature and humidity data, check bits are not considered;
    dat[i] = read_data();
  pinMode(DHpin, OUTPUT);
  digitalWrite(DHpin, HIGH); //After the completion of a release of data bus, waiting for the host to start the next signal


void setup()
  pinMode(DHpin, OUTPUT);



void loop()

  lcd.setCursor(1, 1);
  lcd.print("Humdity = ");
  lcd.print(dat[0], DEC); //Displays the integer bits of humidity;
  lcd.print(dat[1], DEC); //Displays the decimal places of the humidity;
  lcd.setCursor(1, 2);
  lcd.print("Temperature = ");
  lcd.print(dat[2], DEC); //Displays the integer bits of temperature;
  lcd.print(dat[3], DEC); //Displays the decimal places of the temperature;


What chip is on your backpack (8574, 8574A, 8575, 9555 or something other)?
You should check the address of chip (0x27), maybe another.
I2C Port expanders - 8574, 8574A, 8575, 9555 etc
Have you tried changing the contrast using the potentiometer on the backpack?

  • make a clear picture of your setup and upload it to the forum. one from the backside, one from the front, we need to see ALL wires.
  • Check with an I2C Scanner Sketch if the LCD is responding (can be found in Wire / i2c_scanner ) . What address is seen by the scanner?
  • Start with a simple sketch from the library (e.g. Hello World) - does it work?

I2C scanner in your IDE...file ....examples.

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.

Try and use the code that is in the book. If your wiring is 100% correct, then check the wires themselves. As in, are they making a secure mechanical and electrical connection with the LCD and with the pins on the Arduino. Try using a breadboard instead of male-to-female jumper wires. Check that the Arduino is working properly. Do this by uploading the 'Blink' example sketch and see if the 'L' LED blinks.

Try and turn the contrast knob attached to pin 3 here and there.

If all else fails, use a different Arduino and/or a different LCD.

short after power on, the display fill a half of present lines with black blocks. do you see this?


You have not answered the questions posed to you.

Can you show a picture of the reverse side of the display please?

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

my 1602

but how it helps to topic starter?

But only if the code is not initialising the display.

Easiest to set the contrast first with SDA and SCL disconnected.

I suspect Tom may have been asking the OP rather than yourself. :grin:

8574 or 9555 and the address is 0x27
the contrast only changes the screen brightness

Sorry, i have been really busy with my classes

Sorry, the contrast control does not alter the screen brightness, which is the backlight. It sets the contrast - the points on the screen which will show your text when you have the code working but first you need to disconnect SDA and SCL, power up the display and adjust the contrast control until you clearly see the display kolaha illustrates:

Once you have that, you can reconnect SDA and SCL, power up the Arduino and if your code is working you will get your text. If you only get the "blocks" again, then your code is not accessing the display.

Thank you, everyone, for helping,
I will upload the code I used and a picture of the LCD working sometime soon

@agent_pup, your topic has been moved to a more suitable location on the forum.