Connecting and Using A Text LCD Display: Problem
Connecting and Using A Text LCD Display: Problem
Problem
You have a text LCD based on the industry-standard HD44780 or a compatible
controller chip, and you want to display text and numeric values.
Solution
The Arduino software includes the LiquidCrystal library for driving LCD displays
based on the HD44780 chip.
Figure below shows the most common LCD connections. It’s important to check
the data sheet for your LCD to verify the pin connections. Table below shows the
most common pin connections, but if your LCD uses different pins, make sure it
is compatible with the Hitachi HD44780—this project will only work on LCD
displays that are compatible with that chip. The LCD will have 16 pins (or 14 pins
if there is no backlight)—make sure you identify pin 1 on your panel; it may be
in a different position than shown in the figure.
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 Students");
}
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);
}
Formatting Text
Problem
You want to control the position of text displayed on the LCD screen; for example,
to display values in specific positions.
Solution
This sketch displays a countdown from 9 to 0. It then repeat the sequence and
display on the LCD:
/*
LiquidCrystal Library - FormatText
*/
#include <LiquidCrystal.h> // include the library code:
//constants for the number of rows and columns in the LCD
const int numRows = 2;
const int numCols = 16;
// 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);
}
void loop()
{
lcd.begin(numCols, numRows);
lcd.print("Starting count"); // this string is 12 characters long
for(int i=9; i >= 0; i--) // count down from 9
{
// the top line is row 0
lcd.setCursor(15,0); // move the cursor to the end of the string printed above
lcd.print(i);
delay(1000);
}
}