BTC Optical Mouse Hack

A while back, I happened upon the application note "Interface to Optical Mouse Sensor" on the Kronos Robotics website. It discusses the application of a sensor from an optical mouse for use as a position sensing coprocessor on a robot. The application note did not go beyond the proof-of-concept stage. It did not describe how to use all of the functions of the Agilent mouse sensor, which are available through a direct interface to the mouse sensor. It turns out that there are many functions available in the Agilent mouse sensor that cannot be accessed through the PS2 interface.

I didn't have easy access to the GE mouse described in the Kronos Robotics application note. I had to find another optical mouse that employed an Agilent optical mouse sensor. I also wanted to go beyond the proof-of-concept stage and acutally use the mouse sensor in a robotics application. Before developing that application, though, I first had to gain familarity with interfacing directly to the Agilent optical mouse sensor and accessing its functions from within my Forth environment. This webpage describes the hack I did to a BTC optical mouse to enable direct control of the Agilent (now Avago, see below) ADNS-2610 Optical Mouse Sensor and the Forth code written to control it

Inside the BTC M850 3D Optical Mouse

BTC (Behavior Tech Computer) is a Taiwanese manufacturer of low-cost computer peripherals and consumer electronics devices. They have sold a wide range of mice, including standard ball mice, optical mice, and (apparently) laser optical mice. The M850 is a three-button and scroll wheel optical mouse. The packaging, illustrated to the right, calls the mouse as a "3D Optical Mouse", though it really is justs a typical optical mouse. Perhaps, the "3D" capabilities are derivied from the KeyMaestro software on a floppy disk that (sometimes) comes with the mouse. I found this mouse at Fry's Electronics and they usually have plenty in stock (2005 - 2006 time frame). While the Fry's price sticker shows a $6.99 price tag, it is often on sale for $4.99 (one per customer please!). Note the "Agilent enabled" label and the M850 model number at the top of the box front, as these are important to ensuring that you get the correct BTC mouse. Note that Agilent Technologies has spun off its optical mice components to Avago Technologies, so if BTC continues to use the same optical mouse sensors in the future, the packaging may change.
The M850 mouse has a rounded, ergonomic body. The right and left mouse buttons are formed by a single, wrap-around plastic element that is flush to the body. The mouse wheel extends out of the center-front of the mouse body. The wheel is smooth, but easily rotated and pressed. I've seen two mouse color styles: dark grey body and cord with a white mouse wheel and black body and cord with a black mouse wheel. The plastic element for the mouse buttons is always silver in color. The M850 box literature mentions the availability of mice with either a PS2 connector, a USB connector, or a PS2 connector with a USB adaptor. I've only seen the version with the PS2 connector sold at Fry's Electronics.
The bottom of the mouse is unremarkable. Just a label describing the product and its compliance with various governing organization. Access to the guts of the mouse is accomplished by first removing the two metal screws located on the the right and left of the bottom rear of the mouse. The mouse button element must also be released by unclipping it by pressing the hook on the far back end of the bottom of the mouse. The base of the mouse is then removed by sliding it back and away from the body shell of the mouse. Be careful that the mouse button element does to re-clip itself back to the base of the mouse.
Once the mouse body shell is removed the guts of the mouse are clearly visible and accessible. There is not much to look at. The printed circuit board holding the mouse electronics is easily remove by unwrapping the mouse cord from the built-in strain relief in the base of the mouse and lifting the board out.
With the printed circuit board removed, you can see the Agilent (Avago) HDNS-2100 Solid-State Optical Mouse Lens. The lens actually consists of the focusing lens for the mouse sensor and a light prism that directs the light from the illuminating LED onto the viewing surface.
The printed circuit board is a simple, single-sided affair. The microswitches of the mouse buttons and the rotary encoder of the scroll feature are to the front of the board. The electronics for the optical mouse sensor are to the rear. The sensor itself figures prominently in the center. The clear plastic clip is the Agilent (Avago) HDNS-2200 Solid Statte Optical Mouse LED Assembly Clip. It holds the LED at the correct position to shine into the light prism of the HDNS-2200. The part of the clip over the mouse sensor acts as a plastic spring that keeps the clip and lens assembly aligned. Note that this printed circuit board supports two BTC products: the M850 and the M860 (4D Optical Mouse). There are silk screen markings and solder pads for two more microswitches.
The circuit side of the printed circuit board is the typical maze of narrow traces. One unique feature is the that the mouse controller processor chip is attached using chip on board (COB) technology. The chip is hidden under the round black blob of epoxy at the center of the board. The other (obvious) unique feature is the bottom of the optical mouse sensor. The small hole at the center of the round extension of the sensor is the optical aperture. The light from the illuminating LED reflects off the target surface and is focused by the lens onto the sensor array through the optical aperture.

Modding the Mouse

With the mouse completely disassembled, it is now time to modify the wiring to allow direct control of the optical mouse sensor. This is actually very simple to do. The idea is to cut out the "middle man" (the mouse controller) and wire the mouse cable's data and clock lines directly to the optical mouse sensor. Refer to the circuit illustration to the right.

The red dots near the sensor indicate where traces are cut to decouple the data and clock signals from the mouse controller. The red dots below the mouse controller indicate the leads of two inductors (labeled L1 and L2 on the component side of the board) that need to be unsoldered from the circuit. Note that the other pins of the two inductors are also disconected from the traces that lead to the cable's data line (white wire) and clock line (green wire). These lead holes need to be cleared for the insertion of new wires.

The yellow lines indicate the new wiring between the mouse sensor's data and clock lines and the mouse cable's data and clock lines. The wire attachment point for the sensor's data signal is an unused lead hole that must be cleared first. The wire attachment point for the sensor's clock signal is made by scraping away some of the solder mask off the indicated trace and lap soldering the wire to it.

The mouse controller is also removed by cutting away the epoxy blob and removing the chip. This is most easily done by grinding the epoxy off using a rotary tool. Before performing the modifications, it is strongly advised that you cover the optical aperture of the mouse sensor to prevent foreign objects (dust, solder, etc) from getting onto the sensor array or blocking the aperture. I covered the aperature with a paper dot, created by a hole punch, followed by tape to hold the paper dot in place.
The two pictures to the right show the finished modifications. I was almost too agressive with the rotary tool while removing the mouse controller chip. I succeeded in not only removing the epoxy and the chip, I almost removed the underlying printed circuit board as well. Fortunately, I didn't need to use the surrounding circuit traces. The unused microswitches and rotary encoder were harvested from the mouse for use in other robotics projects. The wiring was done using 30-gauge wire used for wire-wrapping.

In retrospect, I probably didn't need to remove inductors L1 and L2, though doing so made it easier to attach the wires. The inductors are probably used to condition the signals traveling on the mouse cable. The mouse cable was originally about five feet in length. I shortened it to a bit less than three feet in length. Losing the inductors didn't appear to have much of an impact for my testing. YMMV.

I fashioned a new connector at the end of the shortened mouse cable to plug into my robot. I won't show it here, but what you'll need to do is provide 5 volts power (red wire), ground (yellow wire), and the mouse data and clock signals. If you want to use the original PS2 connector for this purpose, that is fine. You may want to keep inductors L1 and L2 in place if you retain the original cable length. Remember that the data and clock signals on the PS2 connector are now connected directly to the mouse sensor. After this mod, the signals on the PS2 connector are no longer compliant to the PS2 mouse standard.

The mouse, once reassembled, is now ready for experimentation!

Optical Mouse Sensor Control

My testing of the mouse sensor was performed using a Harris RTXEB single board computer, which is based on the Harris RTX2001A Real-Time Express microcontroller. Consequently, the test code presented below is written in Forth. I believe that the code is sufficiently commented that it could be easily rewritten in another programming language.

The mouse sensor is accessed through a parallel port placed at address 0x1A on the G-bus of the RTX2001A microcontroller. Only a few bits of the port are actually used because of the synchronous serial data interface of the ADNS-2610 optical mouse sensor. Listed below are the definitions of the bits of the G-bus data (GD) used by the synchronous serial data interface:

GD0 (write) - Serial Clock (\SCK)
The inverted serial clock used to shift data into and out of the optical mouse sensor.
GD0 (read) - Serial Data Input (SDIO)
Input data read from the optical mouse sensor.
GD1 - Data Direction Control
Flow control for data shifted to or from the optical mouse sensor (0 input, 1 output).
GD7 - Serial Data Output (SDIO)
Output data written to the optical mouse sensor.

The Forth code is written using the built-in RTXEB Forth interpreter, EBFORTH. While this interpreter is mostly compliant with the Forth 83 standard, some of the instructions are specific to the RTXEB. These are described as follows:

G! ( n g -- )
Writes a value n on the stack into a specified G-bus port address g and removes the value from the stack.
G@ ( g -- n )
Read a value from a specified G-Bus port address g and pushes it onto the stack.
H ( -- addr)
The address of a variable containing the next available dictionary location for code.
H-FENCE ( -- )
The address of a variable containing the beginning address of the user dictionary (the default is 0x4400).
HEX ( -- )
Sets the numeric input-output conversion base to sixteen.
R ( -- )
The address of a variable containing the next available memory location for variables.
R-TOP ( -- )
The address of a variable containing the maximum memory address for variables (the default is 0x43FE).

The Forth code listing defines the Forth words used to implement the synchronous serial data interface that sends and receives data from the ADNS-2610. The serial clock on bit GD0 is inverted because the mouse sensorconsider an idle clock to be held at the high state. For my implementation of the interface, it was easier to invert the signal to assume a low level for the clock idle state. Data that is received from the mouse sensor is delivered most-significant bit first. As sequential bits of data are read in on bit GD0, they are left-shifted to move them into bits of greater significance. Data that is sent to the mouse sensor are also delivered most-significant bit first. Therefore, the data output is aligned to bit GD7. As sequential bit are written to the mouse sensor, the next least-significant bit is left-shifted so it is ready to be written to bit GD7 as well. The data direction control on bit GD1 controls the direction of data written to or read from the mouse sensor. The synchronous serial data bus is bidirectional.

A number of Forth words were written that encapsulate the operations needed to exercise the various registers of the ADNS-2610. The words mirror the register functions described in the ADNS-2610 documentation. With the words the mouse sensor's operational state can be controlled and monitored, the motion counts can be read, the image surface can be evaluated, and the individual pixels of the image can be retrieved.

The animated GIF image to the right shows a sequence of three images taken with the mouse sensor sitting on top of the "Group 3" lines of a USAF Lens Test Chart. Please forgive the quality of the test chart, as it was created with a laser printer. It is not a high-quality photographic film or a metal stencil.

Now that the optical mouse chip can be accessed and controlled directly, it can be used to experiment with to develop new applications for robotics.

2006, 2007 Mac A. Cody

Last updated Friday, March 9, 2007