PS2 mouse - converting delta x/y to mm

Hello, I'm trying to use PS2 mouse as simple odometry for my project.
I used p2 library and I'm getting values from -127 to 127 in both directions.

I modified mouse_init a little bit so I can set own resolution and sampling rate like it's shown on wiki
click

The question is how this affects my mouse measurements.

800dpi mouse

I'd be greteful for help

Is the -127 to 127 the speed at which the mouse is moving? If so, you will have an extremely hard time converting that to distance.

-127 and 127 are some kind of counters which represent the mouse's offset relative to its it's previous position

e.g if you don't move a mouse for a short time it resets back to 0 0
http://playground.arduino.cc/uploads/ComponentLib/Intellimouse.txt

So considering that mouse is 800dots per inch (2,54cm=25,4mm)
by simple equation I got that each step represents movement of 0,03175mm multiplied by 127
equals about 4,03mm maximum in each direction
I was just wondering if sampling rate or resoution affects these calculations

Sampling rate might cause some issues. But what happens if the mouse goes out of the -127 to 127 range?

Well, if you move mouse too fast you get max 127 counts in each direction which results in inaccurate measurement due to some not being recorded.

According to wiki ps2 interface, the range should be -255, 255 - it's 9 bit two complement intiger.
However ps2 library uses chars as variables which are 8 bits. Any solution how to add that 9th bit? This should result in doubling maximum distance before going out of range

You could go into the library and change them to int or long. Int goes up to 65,536 + or -. That should work. However, the mouse might output in chars. Try messing with it and post the results. :slight_smile: