Power Requirements
The LCD & Keypad Shield requires a good 5V power supply to ensure the backlight fully illuminates and the display contrast is high, and if you power your Arduino from USB with the LCD Shield attached you may experience a voltage drop over the USB cable. If you have trouble with display contrast or backlight brightness, try attaching a power supply of around 7 to 9Vdc to the 2.1mm DC jack on the Arduino. A typical symptom in an undervoltage situation is that one line of the LCD will show pale rectangles in place of the characters, and the other line will show nothing at all. The Arduino may even continue running normally because it’s quite happy at just 4V or so, but the LCD & Keypad Shield won’t function.
Library Requirements
All the hard work of interfacing with the LCD Shield is handled by the LiquidCrystal library, which is included as part of the official Arduino distribution. You can check whether you have it installed by starting up the IDE and looking under Files -> Examples -> LiquidCrystal. If it exists, you’re good to go.
Minimal Display Example
To start up the LCD and display a message, open a new sketch in the Arduino IDE and paste in the following code:
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
void setup(){ lcd.begin(16, 2); lcd.print(“hello, world!”);}
void loop(){ // your main loop code here…}
Reading The Buttons
Complex Example
The extensive example below combines a number of techniques to demonstrate how to show messages on the LCD, read from the buttons, and change the display message depending on which buttons are pressed.
/*
Example code for the Freetronics LCD & Keypad Shield:
by Marc Alexander, 7 September 2011
This example code is in the public domain.
This program demonstrates button detection, LCD text/number printing,
and LCD backlight control on the Freetronics LCD & Keypad Shield, connected to an Arduino board.
After powerup, the screen looks like this:
|Freetronics 16×2|
|Btn: 0 | <- This time value counts up the number of seconds since reset (overflows at 99)
When a button is pressed, a label appears for it:
|Freetronics 16×2|
|Btn:RIGHT 0 |
Labels are LEFT, UP, DOWN, RIGHT and SELECT-FLASH.
SELECT-FLASH makes the LCD backlight flash off and on when held down.
Pins used by LCD & Keypad Shield:
A0: Buttons, analog input from voltage ladder
D4: LCD bit 4
D5: LCD bit 5
D6: LCD bit 6
D7: LCD bit 7
D8: LCD RS
D9: LCD E
D3: LCD Backlight (high = on, also has pullup high so default is on)
ADC voltages for the 5 buttons on analog input pin A0:
RIGHT: 0.00V : 0 @ 8bit ; 0 @ 10 bit
UP: 0.71V : 36 @ 8bit ; 145 @ 10 bit
DOWN: 1.61V : 82 @ 8bit ; 329 @ 10 bit
LEFT: 2.47V : 126 @ 8bit ; 505 @ 10 bit
SELECT: 3.62V : 185 @ 8bit ; 741 @ 10 bit*/
For more detail: LCD & Keypad Shield Quickstart Guide