Chris Kiick posted about swarm robotics earlier in the week and today publishes his first Hack-A-Day How-To.
Old computer mice are being abandoned in droves. They’re tossed out because of dirt, obsolescence, or for being entirely too beige. Anyone who has a computer usually has more than one mouse and you can get them for pennies, if not free just for asking. Fortunately for the discriminating (read: cheap) hacker, these little widgets are chock-full of project parts. Today’s How-To will dissect a computer mouse, extract the useful parts, and give some ideas about how to use them.
Here we have a standard PS2 mouse; a USB mouse will look pretty much the same. We’ll talk about optical mice later on.
Lets open it up. First, take out the mouse ball. Then there will be one or more screws on the bottom side that need to come out. Screws are sometimes hidden under the rubber pads.
The first thing to notice is the cable connector. Most mice have a very convenient plug for the cable, instead of soldering it onto the board. That’s the first usable part: a 4 (or 6) conductor cable with a nice plug on one end. The socket can be removed from the PCB and used in other projects.
With the cord out of the way, we can start pulling out parts. First thing that pops off is the mouse wheel. Yes, it’s just a big rubber wheel. If you’re annoyed by the mouse wheel’s clicking noise, you can silence it. There are at least two micro-switches and usually a third one under the mouse wheel which can be used for bump sensors or buttons.
Next thing to take out are the two plastic slotted discs. They’re the encoder wheels. They turn whenever the mouse moves and interrupt an IR beam, producing pulses. It used to be that precision encoder wheels were pretty expensive, but not anymore. Every single (non-optical) mouse comes with a pair built in.
On either side of the encoder wheel are some little boxes. One side is an IR emitter, and the other side is a pair of IR detectors. Sometimes the emitters and detectors will be one complete unit. A pair of detectors is used because with 2 detectors slightly offset, it generates quadrature encoding, so that mouse knows the direction of rotation.
These IR emitters and detectors are fairly modular pieces when it comes to hacking and can be removed with some careful desoldering. It is a good idea to use a multimeter to see what kind of voltage is going to them before removing them. They are probably TTL parts, because mice are powered by 5v, but sometimes they are an even lower voltage. The emitter/detector pair by itself can be interfaced directly. Those parts alone can be used for a proximity sensor or for a line following robot.
Add an encoder wheel and this sensor setup has lots of uses. From a tachometer, to a wind speed indicator, to sensing a robot’s speed, this will do it. The quadrature output (with some decoding) can be used to measure distance, direction, and speed.
One tricky thing about using the encoder with the IR sensor is getting the emitter to line up with the detector(s). No problem: instead of desoldering the parts from the PCB, use a rotary tool to cut off the little piece of PCB that has the sensors on it (already lined up). Wires can then be soldered to the pins/traces on the other side. If holding the encoder wheel in place is a problem, a hunk of the mouse casing can be used with it. Be sure to leave enough PCB to keep it stable on the mouse casing.
This is a picture of an encoder wheel with quadrature from a PS2 mouse on a small robot. Rather than make custom parts, the mouse is carved up and the whole assembly is fitted to the motor axis.
What’s left to salvage on the mouse? The sensors for the mouse wheel. Depending on the model, the mouse wheel movement may be sensed with switches or a low resolution encoder, suitable for measuring slow rotation.
The final bit is the mouse controller chip. At first thought it seems pretty useless: it’s a single purpose part made specifically to run a computer mouse and nothing else. However, if your controller chip isn’t an anonymous blob, the datasheet could be very enlightening. Octopart can help find datasheets based on the chip’s part number. This (PDF) is a typical datasheet for a mouse controller.
This specific part does a number of useful things:
- decodes the quadrature input from the encoders
- keeps a running count of the number of encoder pulses in a set of registers
- filters out jitter
- debounces the micro-switches and keeps track of their state
- packetizes the information and sends it up the cord.
For a PS2 mouse, getting at these features is not too difficult. The PS2 protocol is pretty friendly, even for microcontrollers. Here’s an example of interfacing a microcontroller with a mouse. For USB mice, check the controller’s datasheet to see if it can do both PS2 and USB; with older mice there’s a decent chance it does. While pure USB is not very easy to talk to with a microcontroller, it’s really easy to hook to a PC (with the right software).
We promised a look at optical mice. Optical mice do not have any rotary encoders. There are still some switches and a low-res encoder for the mouse wheel. What an optical mouse has in it is a mini-camera, lights, and lenses. The light is probably a fairly standard LED, although they tend to be bright, and the lenses are purpose built. However, it is possible to interface directly to the mini-camera or use it as a really poor scanner.
We hope this How-To has sparked some ideas and that your obsolete mouse won’t seem as useless anymore.