Maandelijks archief: november 2013

I wanted to experiment with a optical mouse sensor, did a websearch, found this blogpost, and adapted the code for my A2620 mouse sensor. As it might be useful to others, below is my Arduino sketch and the processing sketch.

Use the processing sketch to view the image from the sensor, or use a terminal program to ask it for X / Y movement.

(Yes, that thing to the left used to be a mouse… The thing to the right is an avrdb-m328 board used as an Arduino)

The serial I/O routines are apparently the same across several Avago chips.
It would be a good idea to reimplement this code in C++. The primary difference
between, say, the ADNS2610 and the ADNS2051 are the schemes they use to dump the data
(the ADNS2610 has an 18×18 framebuffer which can’t be directly addressed).

This code assumes SCLK is defined elsewhere to point to the ADNS’s serial clock,
with SDIO pointing to the data pin.

//Ask for a frame dump
writeRegister(regPixelData, 0x2A); // wite anything to pixeldatareg to start at first pixel (A2620)

val = 0;
pos = arr;
uBound = arr + 325;

timeout = millis() + 1000;

//There are three terminating conditions from the following loop:
//1. Receive the start-of-field indicator after reading in some data (Success!)
//2. Pos overflows the upper bound of the array (Bad! Might happen if we miss the start-of-field marker for some reason.)
//3. The loop runs for more than one second (Really bad! We’re not talking to the chip properly.)
while( millis() < timeout && pos < uBound)
{
val = readRegister(regPixelData);