Hey guys,
i have a project which use 4 ps/2 mouse.
I use this library.
I tested 1 mouse with the example code and it works.
However when i tried the code again with the same mouse it doesnt transmit anything, so i figured it must be stuck on some part. Looks like the arduino stuck on this part:
void PS2Mouse::write(int data) {
char i;
char parity = 1;
pull_high(_data_pin);
pull_high(_clock_pin);
delayMicroseconds(300);
pull_low(_clock_pin);
delayMicroseconds(300);
pull_low(_data_pin);
delayMicroseconds(10);
pull_high(_clock_pin); // Start Bit
while (digitalRead(_clock_pin)) {;} // stuck on this part.
// clock is low, and we are clear to send data
for (i=0; i < 8; i++) {
if (data & 0x01) {
pull_high(_data_pin);
} else {
pull_low(_data_pin);
}
// wait for clock cycle
while (!digitalRead(_clock_pin)) {;}
while (digitalRead(_clock_pin)) {;}
parity = parity ^ (data & 0x01);
data = data >> 1;
}
executed when running this:
void PS2Mouse::initialize() {
pull_high(_clock_pin);
pull_high(_data_pin);
delay(20);
[b]write(0xff); // Send Reset to the mouse[/b]
read_byte(); // Read ack byte
delay(20); // Not sure why this needs the delay
read_byte(); // blank
turns out the mouse clock were never low.However when i change the pull_low code from:
void PS2Mouse::pull_low(int pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
}
to
void PS2Mouse::pull_low(int pin) {
pinMode(pin, INPUT);
digitalWrite(pin, LOW);
}
It sorta works, but the output never changes, and the Serial.println() always take 5 seconds where theres no delay() in the loop
i tried with the other 3 mouse but the result always the same. can anyone help?
Heres the example code:
/**
* Reads X/Y values from a PS/2 mouse connected to an Arduino
* using the PS2Mouse library available from
* http://github.com/kristopher/PS2-Mouse-Arduino/
* Original by Kristopher Chambers <kristopher.chambers@gmail.com>
* Updated by Jonathan Oxer <jon@oxer.com.au>
*/
#include <PS2Mouse.h>
#define MOUSE_DATA 5
#define MOUSE_CLOCK 6
PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA, STREAM);
/**
* Setup
*/
void setup()
{
Serial.begin(38400);
mouse.initialize();
}
/**
* Main program loop
*/
void loop()
{
int data[2];
mouse.report(data);
Serial.print(data[0]); // Status Byte
Serial.print(":");
Serial.print(data[1]); // X Movement Data
Serial.print(",");
Serial.print(data[2]); // Y Movement Data
Serial.println();
}