|
I'm always looking for interesting ways to interface computers and embedded devices to the outside world, and ran across some projects where people had hacked an optical mouse to use as a scanner. This was very interesting to me, since most methods I had used to allow projects to interact with the outside world were physical in nature (buttons and piezoelectric transducers). An optical sensor allows the projects to "see", which is fascinating, also allowing you to get important data such as speed, direction, and distance. It should be noted that these measurements will not be exact (within +- 0.5% per the datasheet and my own observations), but will suffice for many projects.
The circuit and communication to the sensor are fairly simple - the hardest part is to locate an optical mouse that contains an ADNS-2610 optical sensor in it. I've bought, destroyed, and thrown away many optical mice looking for this component before I finally wised up and bought some ANDS-2610 sensors directly from Mouser or Digikey. I figured $2 for the chip beat playing roulette by buying a $15 mouse that may or may not have what I'm looking for. The problem with this method is that one of the components that is necessary to make the ADNS-2610 work properly is the HDNS-2100, which is a component that you attach the ADNS-2610 to that provides a lense for the sensor and directs the LED light to the lense at the proper angle. You can buy them from Mouser if you need around 7,000 of them, but that was a little much for me. I found a supplier in the UK that sells them in single quantities, which is Farnell. The prices are not bad, but you have to remember that the prices are in pounds and you have to pay higher shipping to get them over the pond. There's also a 20 pound minimum order. They've got a good selection of components, so just use them next time you're making an order you would ordinarily send to Digikey, and you won't be too bad off. I tend to break alot of things, so I ended up spending the whole 20 pound minimum on something like 150 of these things so that I would never run out. It ended up being the same price as about 3 optical mice, which isn't all that bad.
Below is the typical circuit that I use. I have typically used this with the Microchip PIC16F690, using the Hi-Tech C compiler. I've added sample code below to illustrate a simple routine used to read and write from the registers.
ADNS-2610 communication involves only two connections to the microcontroller: a clock and a data in/out line. The ADNS-2610 datasheet describes the timing of communication well. Note that the delays described between operations are critical to the ADNS-2610 working appropriately. The 2610 has an "LED Control" pin, that will turn the LED off after one second of inactivity, presumably for power preservation. I have not used this feature in any circuits I've made, but I do usually attach an LED (other than the one for illumination) between the LED control pin and ground. You can use this LED to ensure that the ADNS-2610 is working properly by setting the setting/clearing bit 1 of the configuration register. This turns the "forced awake" mode on and off. With the LED wired in the configuration above, setting the first bit will turn the led off. Clearing this bit will cause the LED to turn off when motion is detected, and turn off after 1 second of inactivity. Remember that I'm referring to my "indicator" LED and not the illumination LED.
You can get several data items from the ADNS-2610, such as:
- Movement along the X axis (register 3)
- Movement along the Y axis (register 2)
- The actual image seen by the sensor (register 8)
- Several others that I don't quite understand yet
Each of these data items are stored in its own register. To access the register you clock in the register address, wait the required setup time for the ADNS-2610 to retrieve the data, then clock out the data from the ADNS-2610 to your microcontroller (8 bits of data). The movement data for the X and Y axis is formatted as signed integers, meaning that 1 to 127 indicates a positive movement of that amount, while 128 to 255 indicate a negative movement of -128 to -1. The image stored in register 8 is clocked out one pixel at a time, over 324 frames (18 x 18 resolution). The first pixel is indicated with a MSB value of "1". Each pixel is 6 bits of grayscale, and the 6th bit contains a "1" as long as the pixel contains valid data. Just iterate through the pixels until you get a value of 128 or higher (indicating the first pixel), then clock out the next 323 pixels to get the complete image.
Click here for the code to used to write data and retrive data from the ADNS-2610, written in Hi-Tech C for the Microchip PIC16F690.
|