Can an old laser mouse be used as an encoder

February 07, 2021


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.


Hardware


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.


Avago A5020E


Firmware


Based on the articles here PS/2 Mouse/Keyboard interface and signals PS/2 signals I wrote some firmware for the stm32g4 in Zig to read and decode the mouse signals.




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.


Results


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.


Mouse DPI vs Surface


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.


Cheers!