#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
but after uploading my code, i am getting like below:
after this if a dark squares appear on 1st row of lcd then proceed further
lcd 4th pin -> digital pin 9
lcd 5th pin -> GND
lcd 6th pin -> digital pin 8
lcd 11th pin -> digital pin 5
lcd 12th pin -> digital pin 4
lcd 13th pin -> digital pin 6
lcd 14th pin -> digital pin 7
now run this code
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 5, 4, 6, 7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
You should only be using lcd.begin once, in setup since the LCD module only needs to be initialized once..
You don't need lcd.clear immediately after lcd.begin since it is done as part of the initialization.
The strange display shown in your photograph is not due to improper wiring or code, it is usually caused by a bad connection between the display and the pc board on which it is mounted. Don't be surprised if it reappears.
Try using some simple code instead of your LcdPrint function:
#include <LiquidCrystal.h>
//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // put your pin numbers here
void setup()
{
lcd.begin(16, 2); // put your LCD parameters here
lcd.print("hello, world!");
lcd.setCursor(0,1);
lcd.print("it works!");
}
void loop()
{
}
I don't know why you are doing what your are with the String object and functionalizing the lcd.print but it is causing your problem.
lcd.print() will not accept a void function as an input. You have typed LcdPrint(String x) as an int. I don't know why but it is returning the value of 12. I hope someone can explain this.
If you change the function type to char and have it return a space (char 32) the mysterious 12 goes away. The cursor is positioned after the space.