High resolution encoders are expensive... old computer mice are dirt cheap.
So can a PS2 mouse be used as an encoder? If so, it'd be nice to make a cheap DRO for a mill / lathe. So I bought a pack of mice off of ebay to find out.
It uses an Avago ADNS-5020-EN (marked A5020E on the IC) optical sensor which is no-longer available anywhere but the datasheet can be found by searching.
The code is interrupt based. It first initializes the mouse using "blocking" calls then attaches an interrupt handler on the falling clock signal to decode the data and trigger movement packets.
Unfortunately, while the resolution is good the accuracy is not.
In my testing I found that, the resolution depends on the surface. On the red place mat shown in the picture above moving 1 loop of a 1 thou dial indicator (0.100") gives a count of 80 which equates to 800dpi. Changing to a white piece of paper causes the same movement to count 100.
The datasheet confirms that different surfaces cause the dpi to vary.
Also even on the same surface moving a given distance and then back to the start seems to have error of about 1% (though a part may be due to my test itself). When moving 1ft forward along a ruler then 1ft back to stop to the original position the error is anywhere from 100-200 thou (start and stop at a fixed wall).
Finally it does not detect very slow movements.
In summary, while the resoultion is good, they're not accurate enough to be used as an encoder for a hobby cnc machine.
Some online searches seem to agree with this.
Still a fun project and interesting topic to learn about. Now I can use a mouse/keyboard on any future stm32 projects in zig.