While working on a library to decode the signal from an ADNS 3080 mouse sensor, I needed to develop a system to visualize the images from its camera. This was critical because, without being able to see the image, it was challenging to focus the camera. Proper adjustment was essential for achieving optimal motion tracking. I initially tried using a special output from the sensor called the SQUAL value, which measures surface quality. However, this value did not change much with focus and varied significantly with illumination, making it unhelpful for focusing the camera. Thus, it became necessary to view the images directly.

image

Cameras produce the best images when objects are in focus

I chose to use Python to render the images, as it has many libraries that simplify converting data from an arduino to a display on a computer. Since the serial data from the camera arrived as an array, I needed to decompose the array into two dimensions to generate an image. I utilized the Tkinter library to create a grid of boxes whose colors could be changed. Each box could range from white to black, with various shades of gray in between. One drawback of this system was its high computational load. Decomposing the array required two nested for loops to modify the Tkinter elements. Python is known to be slow with for loops, resulting in a low refresh rate for the images. The Python script also worked in conjunction with an anduino sketch that transmitted the sensor readings via a serial port. Both scripts needed to operate at the same baud rate and use the same begin character. This character controlled when the Python script started and stopped receiving information from the Arduino, which flattened the sensor readings into an array.

When the program sent the begin character, a new position on the y-axis was specified, and the x-axis was scanned for that position. The character-by-character data transmission via the serial port, combined with the slow double for loop in the Python script, resulted in sluggish image rendering. Due to this lag, the system was not well-suited for real-time camera observation. However, it worked sufficiently for focusing the lens on a fixed image. A properly focused camera should generate images like these:

1 / 3
2 / 3
3 / 3

Snapshots from the low-resolution camera

Github repository

The repository contains a Python script and an Arduino sketch to render the output of an ADNS3080 mouse sensor as a grayscale image. The script was written in Python 3 and requires the pyserial library. The Arduino sketch utilizes the ADNS3080 library. Credit goes to Lauszus for the inspiration, as the script is largely based on his work.

See: ADNS3080_frame_capture