Using a Character LCD

Author Gravatar Image LADY ADA

Now we must upload some sketch to the Arduino to talk to the LCD. Luckily the LiquidCrystal library is already built in. So we just need to load one of the examples and modify it for the pins we used.

If you've changed the pins, you'll want to make a handy table so you can update the sketch properly.

LCD pin name RS EN DB4 DB5 DB6 DB7
Arduino pin # 7 8 9 10 11 12

Open up the File→Examples→LiquidCrystal→HelloWorld example sketch

Now we'll need to update the pins. Look for this line:

Copy Code
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
And change it to:
Copy Code
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

To match the pin table we just made.

Now you can compile and upload the sketch.

Adjust the contrast if necessary
You can of course use any size or color LCD, such as a 20x4 LCD
Or a black on green
The nice thing about the black on green ones is you can remove the backlight. Sometimes they dont come with one!

Multiple Lines

One thing you'll want to watch for is how the LCD handles large messages and multiple lines. For example if you changed this line:
Copy Code
lcd.print("hello, world!");
To this:
Copy Code
lcd.print("hello, world! this is a long long message");
The 16x2 LCD will cut off anything past the 16th character:
But the 20x4 LCD will 'wrap' the first line to the third line! (Likewise the 2nd line runs into the 4th) This seems really bizarre but its how the LCD memory configured on the inside. This probably should have been done differently but hey that's what we have to live with. Hopefully we'll have a future LCD library that is very smart and wraps lines but for now we are stuck. So when writing long lines to the LCD count your characters and make sure that you dont accidentally overrun the lines!
Last updated on 2014-04-18 at 09.50.40 PM Published on 2012-07-29 at 03.58.38 PM