Continuing serial mouse experimentation

So I’ve been around the web, found many useful resources for how to incorporate my serial mouse to a project. A very special example is the Serial Mouse -> Etch a Sketch project. There, among many other places, I learned the UART protocol for my device is “Microsoft Mouse”-protocol, a standard protocol for serial interface computer mice.

The Microsoft Mouse protocol consists of 3 bytes sent individually as a package of 7 bits per byte (which is not a full byte) in a specific order each time an event occurs on one the mouse’s motion detectors (movement, button press or button release).

Byte 1 |  1   LB  RB  Y7  Y6  X7  X6
Byte 2 |  0   X5  X4  X3  X2  X1  X0
Byte 3 |  0   Y5  Y4  Y3  Y2  Y1  Y0

  • MSB at Byte 1 is always set to indicate the start of a package.
  • LB and RB represents Left and Right button, active high.
  • Y0-Y7 represents movement in Y position in 8 bit 2’s compliment
  • X0-X7 represents movement in X position in 8 bit 2’s compliment

I wanted to test this and started setting it up in LabVIEW using the VISA serial driver. As always, LabVIEW looks like crap when it’s all set up in the block diagram, with little or no possibilities for comments.
To get the full 8 bit value of Y-position i logically AND’ed byte 1 with the binary representation of the Y7 and Y6 bit, then bit-shifted it 4 times to the left, and OR’ed it with the rest of the Y values in Byte 3.

((Byte 1 & 12)<<4) | Byte 3 = Y position, likewise

((Byte 1 & 3)<<6) | Byte 2 = X position

if (Byte 1 & 32) == 32 {Left button press}

if (Byte 1 & 16) == 16 {Right button press}

To check which direction the mouse is moving, I could check if the signed (MSB) bit is high (negative value) or low (positive value). All though, it could be that the signed bit is low when the whole direction “register” is 0, so you would have to test both conditions to get both directions and eliminate the states when there is no movement at all.

Here is the finished front panel

And here is the messy block diagram

And here is a video, hopefully the “LEDs” and animation will be less choppy on a faster computer

Leave a Reply