getis / Arduino-PS2-Mouse-Handler

PS2 Mouse Handler Library for Arduinos
MIT License
9 stars 2 forks source link

Buttons working fine, but no X-Y data? #1

Open joejackson3 opened 2 years ago

joejackson3 commented 2 years ago

This is my first attempt at hacking a mouse with an Arduino. So got my Genius PS2 mouse (DX-110) hooked up to the Arduino Nano, uploaded the code. Mouse initialises OK, reads mouse ID 250, reacts to button presses, but any movement has no effect on X Y values. They stay at 0....

I thought it might be a faulty mouse, but when connecting via a USB adapter to my laptop, it works absolutely fine.

So right now I'm really at a loss, why the X Y movement are not being read, while the programme obviously communicates with the mouse and reads the buttons fine.

GorillaGubben commented 2 years ago

Hey, I'm having the same exact same problem.

My mouse is the Deltaco MS-737 with the OM50ND sensor.

Mouse initializes and gives me ID 250. All three mouse buttons work and I get the button press data. XY and Z data is not transferred correctly, but only shows 0. Mouse works when connecting it to my PC via USB.

@joejackson3 did you have any luck figuring this out?

joejackson3 commented 2 years ago

hi, no luck yet. Hope more people will come forward with possible solutions. Very strange indeed, that it works fine connected to the PC...

getis commented 2 years ago

Hi. I couple of people have reported the same issue. There is a timeout in the read_byte method that might be forcing it to return a zero value. If you replace the return value with 5 or something and see if that's getting triggered. If it is we can try to work out why the data request is timing out. All seems strange that the button data is getting through fine.

joejackson3 commented 2 years ago

Great suggestion. I changed the return value to 5. Now I get the following return: 250:8:0,0,5,0,0,0,0,0,0 It seems that the z_movement value has timed out. But the X and Y movement haven't timed out. Not sure where to next with it?

GorillaGubben commented 2 years ago

Hey, just a quick update. I tried the solution from @getis but got the same result. Z reports a timeout and still no data from X or Y. I also tried numerous modifications to microsecond delays in between the data bit read cycles, delays between each axis byte reading and whatnot but no success.

I started sifting through the forks of the original code and found a version by VladislavsIgnatjevs where the scroll wheel does work, but still no data from X or Y. This is the one:

https://github.com/VladislavsIgnatjevs/PS2-Mouse-Arduino

The "Wheel" example gives me scroll wheel readings from -7 to 7 as it should.

I have also tried several different forks on an Arduino Nano (clone) but with the same results: Buttons work, Z works (with the above version) but XY does not work.

It kinda feels like it's a timing issue or something, or just a crappy mouse sensor...

getis commented 2 years ago

Hi. Thanks for looking at this.

I did play with the timings a bit on my version to try to tighten things up a bit. That may be an issue for some sensors. It seems strange though that the buttons, and z report back data OK and that the communications for the x and y data bytes seems to run through OK but not get any data. These should really time out or give bad data if there was a timing issue.

Is there enough power getting out to the sensor and LED? Maybe it really isn't picking up any movement.

Just a thought!

GorillaGubben commented 2 years ago

Another update before I give up on this:

I tried plugging the mouse to my computer's PS2 port (yes it's that old) using the passive adapter that came with the mouse. It works.

I tried removing all Serial commands (including Serial.begin) entirely from the Arduino code and just made the built-in LED on the Arduino light up if any mouse button was pressed, the scroll wheel scrolled, or the mouse was moved. The buttons and the scroll wheel made the LED light up, moving the mouse did not.

I tried powering the mouse from an external power bank instead of the Arduino 5V pin. Same results, no XY movement.

The red LED in the mouse is lighting up and I think the mouse is picking up movement since the LED gets brighter when I move the mouse around or touch the lens with my finger, then after a couple of seconds with no movement the LED gets dimmer. I guess this is some kind of "power saving" feature, I've noticed it on several other mice.

I think I'll be using a simpler method of detecting motion in my current project and maybe try this one out with another mouse some other time. Anyways, thanks for replying and helping out!

Cheers!

greatidea1 commented 2 years ago

Same problem here, no X and Y movement data. Scroll wheel and all the 3 clicks work fine

To make it seem more realtime, I decreased the millis from 200 ms to 5 ms

Any possible solutions to get the X and Y movement would be highly appreciated

baralgin1003 commented 2 years ago

By default, the sketch works in REMOTE mode, in order for it to transmit axis data, turn on the STREAM mode and reduce the mouse polling period. PS2MouseHandler mouse(MOUSE_CLOCK, MOUSE_DATA, PS2_MOUSE_STREAM); if (millis() - last_run > 80) { last_run = millis(); mouse.get_data(); ... etc...

baralgin1003 commented 2 years ago

Full code with edits(for remote mode) `#include "PS2MouseHandler.h"

define MOUSE_DATA A5

define MOUSE_CLOCK A4

PS2MouseHandler mouse(MOUSE_CLOCK, MOUSE_DATA, PS2_MOUSE_STREAM);

/**

/**

unsigned long last_run = millis();

void loop() { if (millis() - last_run > 80) { last_run = millis(); mouse.get_data(); Serial.print(mouse.device_id()); // device id Serial.print(":"); Serial.print(mouse.status()); // Status Byte Serial.print(":"); Serial.print(mouse.x_movement()); // X Movement Data Serial.print(","); Serial.print(mouse.y_movement()); // Y Movement Data Serial.print(","); Serial.print(mouse.z_movement()); // Z Movement Data - scroll wheel Serial.print(","); Serial.print(mouse.button(0)); Serial.print(","); Serial.print(mouse.button(1)); Serial.print(","); Serial.print(mouse.button(2)); Serial.print(","); Serial.print(mouse.clicked(0)); Serial.print(","); Serial.print(mouse.clicked(1)); Serial.print(","); Serial.print(mouse.clicked(2)); Serial.println(); } } `

joejackson3 commented 2 years ago

Fellow mouse developers, I would not chase the problems you might be having with a particular mouse too hard. You'll sink a lot of time. It turned out to be a mouse problem - I suspect a timing of signal message issue. I've ordered a different PS/2 mouse: HP 600553-002 Optical Scrolling And it works absolutely fine. Save yourself a whole lot of headache and try a different mouse if you do not get X/Y data when reading out the mouse.