You are on page 1of 6

ArduinoLCDKeyPadShield(SKU:DFR0009)

FromRobotWiki

Contents
1Introduction
2Diagram
3PinAllocation
4SampleCode
4.1ExampleuseofLiquidCrystallibrary
4.2ExampleuseofEnhancedLiquidCrystal_I2Clibrary(Notupdated)
5Documents

Introduction
TheLCDKeypadshieldisdevelopedforArduino
compatibleboards,toprovideauserfriendly
interfacethatallowsuserstogothroughthemenu,
makeselectionsetc.Itconsistsofa1602white
characterbluebacklightLCD.Thekeypadconsists
of5keysselect,up,right,downandleft.Tosave
thedigitalIOpins,thekeypadinterfaceusesonly
oneADCchannel.Thekeyvalueisreadthrougha5
stagevoltagedivider.
Note:Version1.1mainupdatesarethebutton
values,whichhavebeingupdatedontheexample
code.Forolderversioncheckthecommentsand
edit,orusetheEnhancedV1.0library

ArduinoLCDKeyPadShield(SKU:DFR0009)

Diagram

LCD&KeypadShieldDiagram

PinOutDiagram

PinAllocation
Pin

Function

Analog0

Button(select,up,right,downandleft)

Digital4

DB4

Digital5

DB5

Digital6

DB6

Digital7

DB7

Digital8

RS(DataorSignalDisplaySelection)

Digital9

Enable

Digital10

BacklitControl

SampleCode
ExampleuseofLiquidCrystallibrary
//SampleusingLiquidCrystallibrary
#include<LiquidCrystal.h>
/*******************************************************
ThisprogramwilltesttheLCDpanelandthebuttons
MarkBramwell,July2010
********************************************************/
//selectthepinsusedontheLCDpanel
LiquidCrystallcd(8,9,4,5,6,7);
//definesomevaluesusedbythepanelandbuttons
intlcd_key=0;
intadc_key_in=0;
#definebtnRIGHT0
#definebtnUP1
#definebtnDOWN2
#definebtnLEFT3
#definebtnSELECT4
#definebtnNONE5

//readthebuttons
intread_LCD_buttons()
{
adc_key_in=analogRead(0);//readthevaluefromthesensor
//mybuttonswhenreadarecenteredatthesevalies:0,144,329,504,741
//weaddapprox50tothosevaluesandchecktoseeifweareclose
if(adc_key_in>1000)returnbtnNONE;//Wemakethisthe1stoptionforspeedreasonssinceitwillbethemostlikely
//ForV1.1usthisthreshold
if(adc_key_in<50)returnbtnRIGHT;
if(adc_key_in<250)returnbtnUP;
if(adc_key_in<450)returnbtnDOWN;
if(adc_key_in<650)returnbtnLEFT;
if(adc_key_in<850)returnbtnSELECT;
//ForV1.0commenttheotherthresholdandusetheonebelow:
/*
if(adc_key_in<50)returnbtnRIGHT;
if(adc_key_in<195)returnbtnUP;
if(adc_key_in<380)returnbtnDOWN;
if(adc_key_in<555)returnbtnLEFT;

if(adc_key_in<790)returnbtnSELECT;
*/
returnbtnNONE;//whenallothersfail,returnthis...
}
voidsetup()
{
lcd.begin(16,2);//startthelibrary
lcd.setCursor(0,0);
lcd.print("Pushthebuttons");//printasimplemessage
}

voidloop()
{
lcd.setCursor(9,1);//movecursortosecondline"1"and9spacesover
lcd.print(millis()/1000);//displaysecondselapsedsincepowerup
lcd.setCursor(0,1);//movetothebeginingofthesecondline
lcd_key=read_LCD_buttons();//readthebuttons
switch(lcd_key)//dependingonwhichbuttonwaspushed,weperformanaction
{
casebtnRIGHT:
{
lcd.print("RIGHT");
break;
}
casebtnLEFT:
{
lcd.print("LEFT");
break;
}
casebtnUP:
{
lcd.print("UP");
break;
}
casebtnDOWN:
{
lcd.print("DOWN");
break;
}
casebtnSELECT:
{
lcd.print("SELECT");
break;
}
casebtnNONE:
{
lcd.print("NONE");
break;
}
}
}

ExampleuseofEnhancedLiquidCrystal_I2Clibrary(Notupdated)
ThislibraryinheritsLiquidCrystalandaddsanothermethod:buttontoreadbuttonpushedonakeypad.
ThisworksontheOldversionoftheboardV1.0
LibraryForum(http://www.dfrobot.com/forum/index.php?topic=31.0)

/*
DFRobotLCDShieldforArduino
KeyGrabv0.2
WrittenbyGlendonKlassen
gjklassen@gmail.com
http://www.sourceforge.net/users/ecefixer
http://ecefixer.tumblr.com
DisplaysthecurrentlypressedkeyontheLCDscreen.
KeyCodes(inlefttorightorder):
None0
Select1
Left2
Up3
Down4
Right5
*/
#include<LiquidCrystal.h>
#include<DFR_Key.h>
//PinassignmentsforDFRobotLCDKeypadShield
LiquidCrystallcd(8,9,4,5,6,7);
//
DFR_Keykeypad;
intlocalKey=0;
StringkeyString="";

voidsetup()
{
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("KeyGrabv0.2");
delay(2500);

/*
OPTIONAL
keypad.setRate(x);
Setsthesamplerateatonceeveryxmilliseconds.
Default:10ms
*/
keypad.setRate(10);
}
voidloop()
{
/*
keypad.getKey();
Grabsthecurrentkey.
Returnsanonzerointegercorrespondingtothepressedkey,
OR
Returns0fornokeyspressed,
OR
Returns1(samplewait)whennokeyisavailabletobesampled.
*/
localKey=keypad.getKey();

if(localKey!=SAMPLE_WAIT)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CurrentKey:");
lcd.setCursor(0,1);
lcd.print(localKey);
}
}

Documents
LCDKeypadShieldSchematicsV1.0
(http://www.dfrobot.com/image/data/DFR0009/LCDKeypad%20Shield%20V1.0%20SCH.pdf)
LCDKeypadShieldSchematics
(http://www.dfrobot.com/wiki/images/a/a7/LCDKeypad_Shield_SCH.png)
Shielddiagram(http://www.shieldlist.org/dfrobot/lcd)
OldlibrariesforV1:
LCDKeypad(http://www.dfrobot.com/image/data/DFR0009/LCDKeypad.zip)
DFR_Key(http://www.dfrobot.com/image/data/DFR0009/DFR_Key.zip)

GoShoppingArduinoLCD&KeyPadShield(SKU:DFR0009)
(http://www.dfrobot.com/index.php?
route=product/product&keyword=DFR0009&category_id=0&description=1&model=1&product_id=51)
Retrievedfrom"https://www.dfrobot.com/wiki/index.php?
title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)&oldid=8201"
Categories: ProductManual DFRSeries Shields LCDs
Thispagewaslastmodifiedon17January2014,at15:34.
Thispagehasbeenaccessed427,073times.

You might also like