Problem with using Liquid Crystal i2c

I am using an Elegoo Nano with a DHT11 Sensor. I want to connect a LGDehome IIC/I2C/TWI LCD 1602 16x2 Serial Interface Adapter to it. On the display, I connected the black to ground, red to 5 volts, SCL to A5 on the Nano, SDA to A4. As you will see in the code, I also am running the DHT11 to a serial port on a monitor. I can get temperature and humidity readings on the monitor, but nothing shows on the lcd except for the 16 blocks when I have the pot turned up. Below is my code:

#include <LiquidCrystal_I2C.h>
#include <dht.h>
#include <Wire.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
//#include <LiquidCrystal.h>

//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal_I2C lcd(0x27, 16, 2);



void setup() {

  Serial.begin(9600);
  delay(1000                             );//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor                                                                                                            

}//end "setup()"

void loop() {
  //Start of Program

  DHT.read11(dht_apin);

  Serial.print("Current humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%  ");
  Serial.print("Temperature = ");
  //                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Serial.print(DHT.temperature);
  Serial.print((int)round(1.8 * DHT.temperature + 32));
  Serial.println(" F ");

  delay(500);//Wait 5 seconds before accessing sensor again.
 // int chk = DHT.read11(dht_apin);
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
  //Fastest should be once every two seconds.

}// end loop()

What am I doing wrong???
Thanks

run an IDC scan to ensure your LCD is found and @ 0x27 (it's the typical default value but can be changed between 0x20 and 0x27 depending on A0,A1,A2 wiring)

This is a very common problem. There are many different I2C LCD displays. one difference is that all of them do not have the same I2C address. Another thing is that not all have the same pin map in terms of the I2C backpack to LCD wiring. You must know and enter into the LiquidCrystal library LCD constructor the right address and pin mapping. It can be a challenge to figure those parameters out.

The hd44780 library, available from the IDE library manager, takes care of finding the address and pin mapping for you. It is the best LCD library available right now.

run an IDC scan to ensure your LCD is found and @ 0x27 (it's the typical default value but can be changed between 0x20 and 0x27)

Or 0x3F, with the range 0x38 to 0x3F, depending on the version of the PCF8574 chip. 0x38 to 0x3F is the A version.

Thank you. I ran the scanner and my address should be 0x27

:o

in SETUP : lcd.begin (16,2); ????????

cherk:
:o

in SETUP : lcd.begin (16,2); ????????

This is an example that I copied from somewhere (Sorry, I don't know where)

If the library you have is the "LiquidCrystal I2C" library you get from the library manager, the examples have

  lcd.init();
  lcd.backlight();

in setup().

This is an example that I copied from somewhere

If you use the examples that come with the library, you won't have trouble.

There are multiple LiquidCrystal I2C, for example try this one from fdebrabander and test this code

#include <Wire.h> 
#include <LiquidCrystal_I2C.h> // https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
LiquidCrystal_I2C lcd(0x27, 16, 2);  //  LCD address to 0x27, 16 cols and 2 lines display

void setup()
{
  lcd.begin();  // initialize the LCD
  lcd.backlight();  // Turn on the blacklight
  lcd.print(F("HELLO JOCARCUB!"));  // print a message
}

void loop() {}

does this work?

Thanks for all the replies. I looked online where I purchased the LCD and found a library that worked. Now the problem is that the data on the LCD doesn't have the same readings as my monitor. The temp shows 2.00 and the humidity shows 3%. The monitor shows 36%humidity and the temp is 72 degrees.
Can anyone point out my error? Thanks
code
#include <LiquidCrystal_I2C_PCF8574.h>
#include <dht.h>
#include <Wire.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;

//LiquidCrystal_i2c lcd(12, 11, 5, 4, 3, 2);
//LiquidCrystal_I2C lcd(0x27, 16, 2);
LiquidCrystal_I2C_PCF8574 lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {

Serial.begin(9600);
delay(1000 );//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor
lcd.init();

}//end "setup()"

void loop() {
//Start of Program

DHT.read11(dht_apin);

Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("Temperature = ");
// Serial.print(DHT.temperature);
Serial.print((float)round(1.8 * DHT.temperature + 32));
Serial.println(" F ");

delay(500);//Wait 5 seconds before accessing sensor again.
int chk = DHT.read11(dht_apin);
lcd.setCursor(0,0);
lcd.writeStr("Temp: ");
lcd.print(DHT.temperature);

//lcd.writeStr((char)223);
//lcd.writeStr("C");
lcd.setCursor(0,1);
lcd.writeStr("Humidity: ");
lcd.print(DHT.humidity);
lcd.writeStr("%");
delay(1000);
//Fastest should be once every two seconds.

}// end loop()
/code

Use code tags to post code - you are no longer a newbie here

To your question look at what you are printing / displaying and ask yourself if this is the same thing...

I see no code tags, my brain shuts down . Edit your post.... last ask

I see Serial.print((float)round(1.8 * DHT.temperature + 32)); and nothing like it for the lcd...

I have cleaned up the code and used code tags. You were right in that the temperature code for the lcd was not like the temperature code for the serial monitor. There was a line of code for the lcd that showed the Celsius temperature, not Fahrenheit. As you can see, I have modified the code so the serial monitor and lcd are in sync.

I have tried to include photos showing both the serial monitor and the lcd which the difference indicates that the monitor shows humidity and temperature accurately, but the lcd shows what appears to be just the first digit.

What am I doing wrong to chop the last digits from the lcd readings. Thanks

#include <LiquidCrystal_I2C_PCF8574.h>
#include <dht.h>
#include <Wire.h>

#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

//The next two lines are commented out for a prior library that didn't work
//LiquidCrystal_i2c lcd(12, 11, 5, 4, 3, 2);
//LiquidCrystal_I2C lcd(0x27, 16, 2);

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

void setup() {
  Serial.begin(9600);
  delay(1000);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor    

  lcd.init();                                                                                                         

}//end "setup()"

void loop() {
 //Start of Program

 DHT.read11(dht_apin);

  Serial.print("Current humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%  ");
  Serial.print("Temperature = ");
  Serial.print((float)round(1.8 * DHT.temperature + 32));
  Serial.println(" F ");

  delay(1000);//Wait 1 second before accessing sensor again.
 
 // int chk = DHT.read11(dht_apin);  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.writeStr("Temp: ");
  //lcd.print(DHT.temperature);
  lcd.print((float)round(1.8 * DHT.temperature + 32));
  lcd.print((char)223);
  lcd.writeStr("F");
  lcd.setCursor(0,1); 
  lcd.writeStr("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.writeStr("%");
  delay(1000);
 
}// end loop()

Here are the photos showing the LCD and the serial monitor.

LCD.png

Serial Monitor.png

Here are your photos:

afb04c102488138c12c0ff113cfae01899ad3927.png

8d88af89f312a517f4f74cf1cbc3caea309387a6.png

If you try this code, what do you see:

#include <Wire.h>
#include <LiquidCrystal_I2C_PCF8574.h>

LiquidCrystal_I2C_PCF8574 lcd(0x27, 16, 2);

void setup() {
  float t = 123.456;
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(“1t = ”); lcd.print(t,3);
  lcd.setCursor(0,1);
  lcd.print(“2t = ”);lcd.print(2*t,3);
}

void loop() {}

I have gone out of town for a couple days, so will try it later on this week. (I am letting you know so you won't think I am ignoring you!!!) :slight_smile:

I’m in no rush and just get notified if you answer otherwise I don’t follow... no worries (but thanks for the thoughts)

I decided to bring my Arduino along on my trip. I just hope TA doesn't think its a bomb with a timer when I fly home!

(BTW, how did you get my photos into the thread> I would like to learn.

#include <Wire.h>
#include <LiquidCrystal_I2C_PCF8574.h>

LiquidCrystal_I2C_PCF8574 lcd(0x27, 16, 2);

void setup() {
  float t = 123.456;
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("1t = "); lcd.print(t,3);
  lcd.setCursor(0,1);
  lcd.print("2t = ");lcd.print(2*t,3);
}

void loop() {}

yields new_LCD.bmp

I changed the code that you sent me to lcd.writeStr instead of lcd.print and now get new_lcd_1

#include <Wire.h>
#include <LiquidCrystal_I2C_PCF8574.h>

LiquidCrystal_I2C_PCF8574 lcd(0x27, 16, 2);

void setup() {
  float t = 123.456;
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.writeStr("1t = "); lcd.print(t,3);
  lcd.setCursor(0,1);
 lcd.writeStr("2t = ");
   lcd.print(2*t,3);
}

void loop() {}

It is losing digits 2 and 3.

Any thoughts?

New_LCD.JPG

New_LCD_1.JPG

To post images read the post pinned at the top of the forum on how to use the forum and also that one specifically

Your images:
new_LCD.bmp:
ee99de73432a74861810c08538ab79ac9526aab4.jpg

new_LCD_1.bmp
0f5e7935a7437b7dfc8e571f26a8f7a880302d21.jpg