I2C+LCD Screen Issues

Hi guys I'm having a issue with my LCD screen and looking for help! I have a I2C screen that's is giving me bad charters. Now this was working at one point in time but after some time I started getting some bad screen charters. Now everything seems to be working in the serial monitor.

Serial Screenshot by Lightshot

Here is my code

//Libraries
#include <DHT.h>
#include <Wire.h> 
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

//ALWAYS USE THIS WITH LCD I2C and Addres 0x3F
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value


void setup()
{
  Serial.begin(9600);
  dht.begin();
  lcd.begin(16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
}

void loop()
{
  
  delay(2000);
  //Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  temp = (temp*9)/5+32;

  
  //Print temp and humidity values to serial monitor
  Serial.print("Humidity: ");
  Serial.print(hum);
  Serial.print(" %, Temp: ");
  Serial.print(temp);
  Serial.println(" Celsius");

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print(" ");
  lcd.print((char)223);
  lcd.print("F");
  lcd.setCursor(0,1);
  lcd.print("Hum:  ");
  lcd.print(hum);
  lcd.print(" %");

  delay(1000); //Delay 2 sec.

}

And this is Hello World

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

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

void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}


void loop()
{
}

Does a simple "Hello World" print to the LCD work ?

You should use pull up resistors and the longer your cable these should be smaller.

indication (you can experiment a bit
10K for up to 20cm (8 inch)
4K7 for up to 40cm (1 feet)
2K2 for up to 80cm (2.5 feet)
1K for up to 160cm (5 feet)

You might consider shielded cable, especially if there is a lot of interference from other devices around.

This exact setup was working! I'm not sure could I have shorted something out? Would not having a resistor cause this? Also the readings are working correctly in serial monitor Screenshot by Lightshot

Tyler5157:
Would not having a resistor cause this?

yes,

Is this what u were referring to? Ive done that with no change to the screen.

From the picture, it appears to be a 2 line display of the 1602 sort. What are these lines from the code intended to do ?

lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");

Im not so sure why that's like that! I used a example hello world in liquidCrystal I2C

Making Progress.. I Think! I remove all lib's and used another "Hello World" These are my results!

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

// Set the LCD address to 0x27 for a 16 chars and 2 line display


void setup()
{
  // initialize the LCD
  lcd.begin(0x27, 16, 2);

  // Turn on the blacklight and print a message.
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.print("Hello, world!");
}

void loop()
{
  // Do nothing here...
}

Is this kinda what your talking about? When I said I might have damaged my board?

No, without pull ups you "damage" the squareness of the signal.

Check this explanation

Bad signal can cause incorrect reading of bits, especially a 0 for a 1

on the screen you have an S where a W should be.
looking at the bit patterns there is one bit not right (above the ^)

S = 0101 0011
W = 0101 0111
          ^

So indeed the screen read a 0 bit where the arduino sent a 1

Guys,
Many of the i2c LCD backpacks have i2c pullups on them.
If you look at the photos you can see them. They are labeled R8 and R9 and are 4.7k which is fine.

I am seeing multiple issues in the code.
In the first post, the two different sample sketches are using two different libraries.
The top one is using fm's NewLiquidCrystal library and the lower one is using the LiquidCrystal_I2C library.
While both libraries have a LiquidCrystal_I2C class, they are different and work differently.
LiquidCrystal_I2C uses a hard coded pin mapping and NewLiquidCrystal allows configuring the pin mapping.
Both are using the same pin mapping.


Not sure what the issue is, but I'd recommend using my hd44780 library.
I created the hd44780 library to make things easier, especially for LCDs using i2c backpacks like this.
The hd44780 library offers a "plug and play" solution for i2c backpacks like that as it will automatically locate the i2c address and automatically determine the pin mapping.

Of particular interest in this case, is the diagnostic sketch that comes with the library, I2CexpDiag.
It will test the i2c signals for pullups and test the backpack and the LCD.

You can install the library using the IDE library manager. (don't install it using a zip file).
You can read more about it on the github page: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library
And the wiki: Home · duinoWitchery/hd44780 Wiki · GitHub
The i/o class for that type of backpack is hd44780_I2Cexp
I'd recommend installing the library, and then running I2CexpDiag to check things out.
Then you can look at the HelloWorld sketch for the hd44780_I2Cexp i/o class to see the needed includes and how to declare the lcd object.

--- bill

After running I2CexpDiag these are my results.

********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 0.9.0
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.5
CPU ARCH: AVR - F_CPU: 16000000
--------------------------------------------------------------------
 A4: digital pin: 18
 A5: digital pin: 19
SDA: digital pin: 18
SCL: digital pin: 19
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
--------------------------------------------------------------------
Scanning i2c bus for devices..
 i2c device found at address 0x3F
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays
 LCD at address: 0x3F | config: P01245673H | R/W control: Yes
Total LCD devices found: 1
--------------------------------------------------------------------
LCD Display Memory Test
Display: 0
 Walking 1s data test: 
 Compare error: addr: 0 read 20 != wrote 1
 Compare error: addr: 0 read 20 != wrote 2
 Compare error: addr: 0 read 20 != wrote 4
 Compare error: addr: 0 read 20 != wrote 8
 Compare error: addr: 0 read 20 != wrote 10
 Compare error: addr: 0 read 20 != wrote 40
 Compare error: addr: 0 read 20 != wrote 80

 Compare error: addr: 40 read 0 != wrote 4
 Compare error: addr: 40 read 0 != wrote 8
 Compare error: addr: 40 read 0 != wrote 40
 Compare error: addr: 40 read 0 != wrote 80

 Compare error: addr: 10 read 0 != wrote 4
 Compare error: addr: 10 read 0 != wrote 8
 Compare error: addr: 10 read 0 != wrote 40
 Compare error: addr: 10 read 0 != wrote 80

 Compare error: addr: 50 read FF != wrote 1
 Compare error: addr: 50 read FF != wrote 2
 Compare error: addr: 50 read FF != wrote 4
 Compare error: addr: 50 read FF != wrote 8
 Compare error: addr: 50 read FF != wrote 10
 Compare error: addr: 50 read FF != wrote 20
 Compare error: addr: 50 read FF != wrote 40
 Compare error: addr: 50 read FF != wrote 80
FAILED
 Address line test: 
 Compare error: addr: 0 read 20 != wrote 0
 Compare error: addr: 1 read 22 != wrote 1
 Compare error: addr: 3 read 2 != wrote 3
 Compare error: addr: 4 read 22 != wrote 4
 Compare error: addr: 5 read 22 != wrote 5
 Compare error: addr: 6 read 20 != wrote 6
 Compare error: addr: 7 read 20 != wrote 7
 Compare error: addr: 8 read 20 != wrote 8
 Compare error: addr: 9 read 22 != wrote 9
 Compare error: addr: B read 2 != wrote B
 Compare error: addr: C read 22 != wrote C
 Compare error: addr: E read F2 != wrote E
 Compare error: addr: F read F2 != wrote F
 Compare error: addr: 10 read 22 != wrote 10
 Compare error: addr: 11 read 22 != wrote 11
 Compare error: addr: 12 read 20 != wrote 12
 Compare error: addr: 13 read 20 != wrote 13
 Compare error: addr: 14 read 20 != wrote 14
 Compare error: addr: 15 read 20 != wrote 15
 Compare error: addr: 16 read 20 != wrote 16
 Compare error: addr: 17 read 20 != wrote 17
 Compare error: addr: 18 read 20 != wrote 18
 Compare error: addr: 19 read 20 != wrote 19
 Compare error: addr: 1A read 20 != wrote 1A
 Compare error: addr: 1B read 20 != wrote 1B
 Compare error: addr: 1C read 20 != wrote 1C
 Compare error: addr: 1D read 20 != wrote 1D
 Compare error: addr: 1E read 20 != wrote 1E
 Compare error: addr: 1F read 20 != wrote 1F
 Compare error: addr: 21 read 20 != wrote 21
 Compare error: addr: 22 read 20 != wrote 22
 Compare error: addr: 23 read 20 != wrote 23
 Compare error: addr: 24 read 20 != wrote 24
 Compare error: addr: 25 read 20 != wrote 25
 Compare error: addr: 26 read 20 != wrote 26
 Compare error: addr: 27 read 20 != wrote 27

 Compare error: addr: 40 read 0 != wrote 40
 Compare error: addr: 41 read 1 != wrote 41
 Compare error: addr: 42 read 2 != wrote 42
 Compare error: addr: 43 read 3 != wrote 43
 Compare error: addr: 44 read 0 != wrote 44
 Compare error: addr: 45 read 1 != wrote 45
 Compare error: addr: 46 read 2 != wrote 46
 Compare error: addr: 47 read 3 != wrote 47
 Compare error: addr: 48 read 0 != wrote 48
 Compare error: addr: 49 read 1 != wrote 49
 Compare error: addr: 4A read 2 != wrote 4A
 Compare error: addr: 4B read 3 != wrote 4B
 Compare error: addr: 4C read C != wrote 4C
 Compare error: addr: 4D read D != wrote 4D
 Compare error: addr: 50 read FF != wrote 50
 Compare error: addr: 51 read FF != wrote 51
 Compare error: addr: 52 read FF != wrote 52
 Compare error: addr: 53 read FF != wrote 53
 Compare error: addr: 54 read FF != wrote 54
 Compare error: addr: 55 read FF != wrote 55
 Compare error: addr: 56 read FF != wrote 56
 Compare error: addr: 57 read FF != wrote 57
 Compare error: addr: 58 read FF != wrote 58
 Compare error: addr: 59 read FF != wrote 59
 Compare error: addr: 5A read FF != wrote 5A
 Compare error: addr: 5B read FF != wrote 5B
 Compare error: addr: 5C read FF != wrote 5C
 Compare error: addr: 5D read FF != wrote 5D
 Compare error: addr: 5E read FF != wrote 5E
 Compare error: addr: 5F read FF != wrote 5F
 Compare error: addr: 60 read FF != wrote 60
 Compare error: addr: 61 read FF != wrote 61
 Compare error: addr: 62 read FF != wrote 62
 Compare error: addr: 63 read FF != wrote 63
 Compare error: addr: 64 read FF != wrote 64
 Compare error: addr: 65 read FF != wrote 65
 Compare error: addr: 66 read FF != wrote 66
 Compare error: addr: 67 read FF != wrote 67
FAILED
--------------------------------------------------------------------
No working LCD devices

And after running hello world from you examples this is what came up. Thanks Again

No point in running HelloWorld when there are issues accessing the LCD RAM.

That type of issue could be caused by soldering issues.

When looking at your photos, I do see some soldering issues.
One the backpack side, there are two pins that look like they have poor soldering.
They are the 6th and 7th pins from the right in the photo.
That would be LCD pins 11 and 10 or DB4 and DB3.
DB3 isn't used, but DB4 is.

Those two pins need to be cleaned up perhaps simply reheating them would get the solder to flow better.

The strange part, at least for me, is the LCD side.
I don't see any pins sticking through the PCB. Normally when a header is soldered to the LCD PCB
a short amount of pin will stick through the PCB. I don't see this on your LCD.
Here is a photo of what I'm talking about:

It looks like the header pins on your backpack were not pushed into the LCD PCB far enough when soldered.
This may be causing connection issues.

--- bill