element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum interfacing a keyboard and lcd screen on arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 402 subscribers
  • Views 801 views
  • Users 0 members are here
Related

interfacing a keyboard and lcd screen on arduino

Former Member
Former Member over 12 years ago

Hi there i have a PS2 keyboard and  simple 16X2 LCD screen

 

does anybody have a source code that make the two interface ?

 

i've tried to write one bymyself using the examples in the arduino (the simple test for the keyboard using the keyboard libraray afcourse and the liquid display libraray)

 

here it is

 

/* in this program I will connect lcd to keyboard and print hello world

 

the circuit  :

LCD -

* LCD RS pin to digital pin 12

* LCD Enable pin to digital pin 11

* LCD D4 pin to digital pin 6

* LCD D5 pin to digital pin 5

* LCD D6 pin to digital pin 4

* LCD D7 pin to digital pin 3

* LCD R/W pin to ground

* 10K resistor:

* ends to +5V and ground

* wiper to LCD VO pin (pin 3)

 

Keyboard -

*Data - pin 8

*Clk - pin 2

*/

 

 

//includes

#include <LiquidCrystal.h>   //LCD library

#include <PS2Keyboard.h>       //Keyboard library

 

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

//initialize the Keyboard

const  int DataPin = 8;

const   int IRQpin =  18;

 

 

PS2Keyboard keyboard;

 

 

void setup() {

              // set up the LCD's number of columns and rows:

              lcd.begin(16, 2);

             //set up the kyeboard to recieve data

  delay(1000);

  keyboard.begin(DataPin, IRQpin);

  Serial.begin(9600);

   

   

           

              Serial.println("Keyboard Test:");

    

}

 

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);    

             //lcd.setCursor(1,1);

              //reading the keyboard and print it to the screen if necessary

              if (keyboard.available()) {

                             // read the next key

                          char(c) = keyboard.read();

              }

                else {

                               // otherwise, just print all normal characters

                                char c = keyboard.read();

                                Serial.print(c);

                }

               

               

               

}

           

              

 

the problem is that the code is complied and also can be uploaded to the arduibo the problem is...it doesnt do what is  suppose to do which is :

 

 

each button i will press on the keyboard will appear  on the lcd

  • Sign in to reply
  • Cancel
Parents
  • mcb1
    mcb1 over 12 years ago

    chen

    I'm picking that it doesn't even display "keyboard test" ?

     

    The code you've copied looks like its writing to a serial LCD, and yours is not (based on the connections in the sketch).

     

    try

    lcd.setCursor(0,0);  // First position (0) and first line (0)

    lcd.print (" Keyboard test ");

     

    instead of Serial.println("Keyboard Test");

     

    and

    lcd.setCursor(0,1);  // First position (0) andsecond line (1)

    lcd.print (c);

     

    instead of Serial.print(c);

     

    if you were to open the Serial monitor at 9600 baud, I'll bet you can see the "Keyboard Test" and then the char you type.

    Trying his first will at least shown if the keyboard is working...

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to mcb1

    thanks !! that did the trick it works

     

    thank you very much

     

    one more question though sorry for being a nag

     

    it writes the notes over the other ones..if i want to that the letters and stuff i type to come one after the other i need to use a for loop?

     

    and one more question how can I define the functions of special keys as space bar and esc and delete (when i try to type delete it writes delete how can i program it to actually delete?)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Former Member
    Former Member over 12 years ago in reply to mcb1

    thanks !! that did the trick it works

     

    thank you very much

     

    one more question though sorry for being a nag

     

    it writes the notes over the other ones..if i want to that the letters and stuff i type to come one after the other i need to use a for loop?

     

    and one more question how can I define the functions of special keys as space bar and esc and delete (when i try to type delete it writes delete how can i program it to actually delete?)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    Chen

    well done

     

    Your loop always resets the cursor to position 0, and so it will overwrite.

     

    The keys all have ascii codes, although not printable.

    (i've never tried it ...)

    You just need to use an if statement (or a switch case) to choose what to do.

     

    ie when you get a space instead of lcd.print(c) try lcd.print(" ")

    for esc if you wanted it to clear everything you have the command lcd.clear(), BUT remember to reset the cursor position ....

     

    For the deleting, you need to know how many letters you have and write a space over the last one.

    There may be options to change text direction, but try knowing what you have entered/displayed so you can use it later in the program.

     

    You can store the entries into an array, or simply make up a string

     

    Have a go, see where you get stuck, you'll learn more than if someone gives you the finished code.

    The various commands available are at http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary

     

     

    Mark

    PS

    You have the option of marking answers correct or helpful, which I believe are visible to you at the bottom (sorry never seen them, only answered not asked)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube