The project uses the PS2 connector to connect the Keyboard with the Arduino board. The PS2 connector has a pin for Data and another pin for Clock and using only these two pins the keyboard communicates with the host device. The mouse always has 6 pin mini-DIN male connector for PS2 interface and the host device always has the corresponding female pin. The images and the pin-outs of the PS2 male and female connectors are shown in the following image, the only difference between the PS2 keyboard and mouse connectors are in their color.
The image of the PS2 male pin
Fig. 2: 6 pin mini-DIN Male connector for PS2 interface
The image of the PS2 female pin
Fig. 3: 6 Pin Mini DIN Female Connector Plug for PS2 interface
The pin-out of the PS2 male and female connectors
Fig. 4: Pin-Out Of PS2 Male and Female Connectors
When it comes to connecting the female connector with the circuit board one should be able to identify the pins at the bottom of the PS2 connector and the following image will be helpful.
Fig. 5: Bottom of Mini DIN Female Connector Plug for PS2 interface
In this project the Arduino pro-mini board is used which is pre-programmed with the Arduino boot-loader Arduino IDE version 1.0.3 on windows operating system. The image of the Arduino pro-mini board and the Arduino IDE is shown in the following;
Fig. 6: Typical Arduino Pro-Mini Board
Fig. 7: Arduino IDE Software Window
Another hardware which can perform the USB to TTL conversion is used to upload the program into the arduino board.
Fig. 8: External USB to TTL converter board for programming Arduino and serial communication
It is assumed that the reader has gone through the project how to get started with the arduino and done all the things discussed in it.The code written for this project uses the custom PS2 library file called “PS2Keyboard.h” which has all the necessary routines for accessing a PS2 mouse and the details of how to use this library to interface a PS2 keyboard is already discussed in a previous project on how to interface the PS2 keyboard with the Arduino. There are basically three functions which the user can directly make use in their code and are namely “keyboard.begin()”,keyboard.available() and “mouse.report(data)”. The details of the functions are discussed in the following.
The function keyboard.begin() is used to perform all the necessary things to initialize an ASCII keyboard using PS2 protocol. Once the initialization is done properly each time a key is pressed the keyboard starts sending the equivalent ASCII value of the key which has been pressed. The function takes one parameter and it is the number of the pin in the Arduino board which acts as the Data pin of the keyboard.
This function can be used to check if a data regarding a key press is available from the keyboard. This function is always called before calling the keyboard.read() function which is used to read the data from the keyboard. The function returns a non-zero positive value whenever a key press is detected.
keyboard.read() returns a non-zero positive value.
The Arduino IDE provides a library called <LiquidCrystal.h> which can be used to interface an external LCD module with the Arduino board. The functions which can be used to access the LCD are already discussed in previous projects on how to interface an LCD, how to display sensor value on LCD, how to connect the LCD with the PC and how to make an LCD scrolling display. With the help of the libraries “PS2Keyboard.h” for interfacing and reading the PS2 keyboard and the library <LiquidCrystal.h> for interfacing and writing into the 16*2 LCD, the code written for this projects simply reads the characters corresponding to the keystrokes and writes the same into the 16*2 LCD.
Before compiling the code make sure that the files “PS2Keyboard.h” and “PS2Keyboard.cpp” are kept in the same folder where the .pde file has been saved. When the coding is finished one can verify and upload the code to the Arduino board as explained in the project how to get started with the Arduino. The LEDs in the keyboard should blink as soon as it is connected with the Arduino board and for each key pressed in the keyboard the same characters can be observed in 16*2 LCD.