A while back I got my hands on an old analog PC joystick, and since then I have been meaning to build an adapter make the joystick work over USB. The adapter I finally built consists of an Arduino connected to a game port I hacked off an old sound card. The Arduino reads the analog (x and y movement) and digital (buttons) inputs and then sends them to the computer over serial. Then a Processing script running on the computer reads the serial data, and converts it into mouse movements and clicks using the Java Robot class.
I first made an adapter to break out the connections from the joystick. I hacked a game port off an old sound card, and wired three sets of connections to it, using the pinout I found. Although the particular joystick I have does not use every available pin, I went ahead an included all of them.
In the picture below, the top three header pins are the 5V and ground connections (red is 5V). The middle four are the analog connections, and the bottom four are digital, for the buttons.
Unfortunately you cannot just plug these pins directly into a microcontroller and get it go read useful information from the joystick. Pull down resistors must be added for each of the button connections. Also, the potentiometers in the joystick do not have their third pins connected to ground, so I had to add a 100k resistor after each of the analog pins, so that the potentiometers act as a voltage divider and the Arduino can read them properly.
In the picture below, orange jumpers are analog, green digital, and the two at the bottom are for 5V and ground:
Pull down resistors:
Everything connected (minus the USB connection to the computer):
The way the code works is fairly simple. The Arduino reads the values of the potentiometers and buttons, scales the values to under 255 (1 byte) so that they can be sent over serial, and then sends the values to the computer over the serial connection.
The processing script running on the computer reads the sequence of numbers being received. It compares the values form the potentiometer to the values when the joystick is centered, and then moves the mouse using the Robot.mouseMove() command based on the difference between the values. Moving the joystick farther one direction means that the mouse will move faster. The trigger button corresponds to left click, and the thumb button is right click. The secondary joystick (top center) is used for scrolling, and the remaining two buttons currently adjust the sensitivity of the joystick.
Due to the speed at which the processing script runs, I had to limit the rate at which the Arduino sent data over serial, because if data was sent too quickly, it backlogged and created a huge lag when moving the joystick. Therefore, the joystick is not quite as responsive as I hoped it would be, and you must hold down the button longer than you would a mouse for your clicks to register. A workaround for this would be to use something like a Teensy, which can be recognized as a HID, so that the microcontroller could control the mouse directly, eliminating the need for an interpreting script.