The PS2 mouse uses a synchronous communication with the PC which is very much similar to the Two Wire Interface protocol. The PS2 connector has a pin for Data and another pin for Clock and using only these two pins the mouse communicate 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 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-loaderArduino 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 “PS2Mouse.h” which has all the necessary routines for accessing a PS2 mouse. There are two functions which the user can directly make use in their code and are namely “mouse.initialize()” and “mouse.report(data)”. The details of the functions are discussed in the following.
The function mouse.initialize() is used to perform all the necessary things to initialize data reporting from a mouse. Once the initialization is done properly the mouse starts sending the data regarding its X-Y movement and the status of the buttons on the mouse. The function takes no parameter and returns nothing but will exist only when the initialization is properly done.
The function mouse.report(data) can be used to read the current data from the mouse. The function should be provided with an integer array of three elements and the function will fill the elements with the required values. The first element is written with the status value, the second element with the X movement value and the third element will be written with the Y movement value.
If there is no movement in the X-Y plane the value for both the second and the third variables will be zero and if there is no button press the first element will be having a value 8. The first element of the array will be having the values 8, 10 and 12 for left-button press, right-button press and center-button press respectively.
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.
Make sure that the files “PS2Mouse.h” and “PS2Mouse.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 and can observe the variations in the X and Y values as the mouse moves and also can find the status of the buttons on the mouse.