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.
//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()
{
}
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
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.
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: