Any AVR microcontroller based board which follows the standard Arduino schematic and is flashed with the Arduino bootloader can be called an arduino board. The arduino boot-loaderThe Arduino board used in this project is the Arduino pro-mini board and the IDE version of the arduino is 1.0.3 for windows.
The image of the Arduino pro-mini board and the Arduino IDE are shown below;
Fig. 2: Typical Arduino Pro-Mini Board
Fig. 3: Arduino IDE Software Window
Since the Arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the Arduino board and also helps in the serial communication with the USB port of the PC.
Fig. 4: External USB to TTL converter board for programming Arduino and serial communication
It is assumed that the reader has gone through the projecthow to get started with the Arduino and tried out all the things discussed there. 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. 5: 6 pin mini-DIN Male connector for PS2 interface
The image of the PS2 female pin
Fig. 6: 6 Pin Mini DIN Female Connector Plug for PS2 interface
The pin-out of the PS2 male and female connectors
Fig. 7: 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. 8: Bottom of Mini DIN Female Connector Plug for PS2 interface
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. 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 values are displayed on the Serial monitor window with the help of the functions Serial.begin(),Serial.print() and Serial.println() which are already discussed in previous projects on how to do serial communication with the Arduino, how to send and receive serial data using arduino and how to do serial debugging with the Arduino. 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 the Serial Monitor window.