dkO,
Your posting reminded me … that it might be feasible to use an optical mouse, reading directly off a machine face and connected to a suitable computer, to read distances to quite small increments. … I downloaded the code associated with the above video, hoping to modify it to suit the RPi and cut a few corners. I failed miserably and all the kit went back in the drawer.
I still think the idea has legs,..
Anyone want to take up the challenge?
John
Well I have too many projects already, and am as sick as dog! But here’s a starter.
In UNIX (including RasperryPi Linux), almost everything is a file. That includes the mouse, so somewhere in the system is a ‘file’ that reports mouse movements. The file can be read by a program in the usual way.
Where’s the file and what is it called? The mouse is an input device, so look in the directory “/dev/input”

Those event files are input streams for the keyboard, mouse and other devices. You can identify which is which by long listing the by-id directory:

As can be seen my system has two mice. The Cherry is the old one and I’ve forgotten to unplug it’s USB wifi receiver. My current mouse is the Logitech, not sure why but it has two event files, event14 and event18. I guessed event14 is the one!
To test it, I read the file with sudo cat /dev/input/event14. (sudo runs cat with super-user privileges.)

Nothing happens until I move the mouse, when a flood of weird characters appear. That’s because the mouse speaks binary, and the screen display program understands characters – it’s baffled!

Piping the binary to character utility helps a little with ‘sudo cat event14 | od -x’:

Mouse events present as a stream of 192 bit binary data structures that have to be decoded:
- 128 bit timestamp (DRO wouldn’t care, CNC might)
- 16 bit event type (Type 0 is a relative mouse move)
- 16 bit event code (Code 0 is relative X, Code 1 is relative Y)
- 32 bit event value (the move distance, X or Y, depending on the event code positive or negative.) This value determines the resolution of a mouse used as a DRO.
So an ordinary program can read the event file as binary, in 192 bit blocks. It would ignore anything that’s not an event type 0, and then decode the structure to get the value of X and Y movements as integers.
That’s as far as I’ve got! I’ll have a go at a C program later. Don’t bet the farm on it working!
The above keeps the programming simple by using the operating system, but the OS might limit the resolution, perhaps to match the users screen. Raw mouse might be better for a DRO, but reading one directly is a challenge. A kernel module is needed and I don’t know how to code them! Might be easier to read Mickey with a microcontroller – dunno.
Dave