I m making a distance measurement using arduino , ultrasonic sensor and i2c lcd.
But after installing code also nothing visible on my screen only upper blocks is visible.
THIS IS MY CODE
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,16,2) for 16x2 LCD.my address is (0x3F)
int trigPin = A0;
int echoPin = A1;
long distance;
long distanceInch;
long duration;
void setup(){
lcd.begin();
lcd.backlight();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.setCursor(0,0);
lcd.print(" WELCOME TO");
lcd.setCursor(0,1);
lcd.print(" MKINVENTIONS");
delay(2000);
}
void loop() {
ULTRASONIC();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("DISTANCE CM:");
lcd.print(distance);
lcd.setCursor(0,1);
lcd.print("DISTANCE INCH:");
lcd.print(distanceInch);
// lcd.setCursor(0,1);
// lcd.print("DISTANCE MM:");
// lcd.print(distanceInch);
}
void ULTRASONIC(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
distanceInch = duration*0.0133/2;
}
I did that also then also its nt working only upper blocks r there .
Even though I have tried a simple hello world cold also but that's also not showing
OK, not sure why Larry is barking up the wrong tree (and Mark just noted, sadly has no idea!).
You are seeing the "blocks" on the first line. That means your contrast control is set more-or-less correctly - good enough in any case.
What the "blocks" mean is that you are not "talking" to the display. Why? Well, using a completely obsolete library, sad to say!
OK, use the Library Manager in the IDE to install Bill Perry's "HD44780" library and then run from that library, the examples > ioClass > hd44780_I2Cexp > I2CexpDiag sketch to find the details for and test your display.
You can then work from one of the sketches in that directory to build what you need to.
I wouldn't DREAM of using the HD44780 library. I have tried that one, but it just ISN'T as good OR easy to use as the one @rajaarin is currently using. @rajaarin, your screen will NEVER display anything with
If that was intended to show exactly which library is being used then it was a failure. All it shows is that the library is named LiquidCrystal_I2C, of which there are several