Keyboard connected to Arduino not working

Hello, I have this simple code for sending characters from a keyboard connected to the Arduino but it does not print the characters I send from the keyboard (connected to the arduino).It only prints "Keyboard Test:".

#include <PS2Keyboard.h>

const int DataPin = 9;
const int IRQpin =  8;

PS2Keyboard keyboard;

void setup() 
{
    delay(1000);
    keyboard.begin(DataPin, IRQpin);
    Serial.begin(9600);
    Serial.println("Keyboard Test:");
}

void loop() 
{
   if (keyboard.available()) 
   {
       // read the next key
       char c = keyboard.read();
       Serial.print(c);
    }
}

What is wrong?

First, which Arduino are you using? The second argument to the begin() method is an interrupt vector and the standard Arduino uses pins 2 and 3 for external interrupts. Second, how do you have the PS2 keyboard attached to the Arduino? Usually, you have to allow for GND, 5V, and the clock and data pins from the PS2 connector. Depending on how it's wired, changing IRQpin to 2 or 3 may make a difference.

Hello, I use Arduino MEGA 2560

But when I use this code,

http://www.icstation.com/newsletter/eMarketing/jianpan.txt

with the same pins

uchar  KB_CLK=8;
uchar  KB_DATA=9;

it works fine.

I use this connection

econjack:
First, which Arduino are you using? The second argument to the begin() method is an interrupt vector and the standard Arduino uses pins 2 and 3 for external interrupts. Second, how do you have the PS2 keyboard attached to the Arduino? Usually, you have to allow for GND, 5V, and the clock and data pins from the PS2 connector. Depending on how it's wired, changing IRQpin to 2 or 3 may make a difference.

I changed it:
pin 9 -> pin 3
pin 8 -> pin 2

and it worked!

The problem now is that pins 2 and 3 were connected to the LCD.
So, how can I use PS/2 and LCD at the same time? Can I use PS2Keyboard.h or should I make new functions ?

The LCD pins don't need to use the external interrupt pins. Find two unused digital pins and move 2 and 3 there and changed the function call that instantiates the LCD object (often called lcd) to reflect the two new pins you selected. For example, you may have had it:

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

Since 9 an 8 are free, try:

LiquidCrystal lcd(12, 11, 5, 4, 9, 8);

and see if that works for you.

Thnx a lot, it worked fine!

Both pins: pin 2 and pin 3 work as interrupts? Do I need both of them for PS2Keyboard to work properly?
For example if I use one of them and another pin for DATA and CLK, will the PS2Keyboard work?
On arduino MEGA do I use any special command to make pin 20 an interrupt? Because it does not work correct.

gewrou:
Both pins: pin 2 and pin 3 work as interrupts? Do I need both of them for PS2Keyboard to work properly?
For example if I use one of them and another pin for DATA and CLK, will the PS2Keyboard work?
On arduino MEGA do I use any special command to make pin 20 an interrupt? Because it does not work correct.

Someone?