Anybody ever interface to a joystick?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I was throwing out old computer parts yesterday - and ran across two old joysticks from wayyy back in the day. I realized that a joystick would be *perfect* for controlling a robot I've been building. One is purely analog (as I opened it up). The other I haven't had a chance to examine but it has an analog/digital switch on it. Both of them have those DB connectors on them - I think about DB15 or so. Has anybody ever interfaced with a joystick? It looks fairly straightforward - but I'd love to hear of what experience yall have with em.

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It'll be very easy... it's just a set of analog pots, and some push buttons. Using some ADC inputs, and some digital I/O's you're all set to go.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Joysticks use POT's, most of the other electronics inside you don't really need. Just gut all the internal electronics accepting for the stick pots and buttons and replaces with AVR circuitry. POT's typically have three terminals, you apply (something like) 5V to one end, and GND the other end and it acts as a voltage divider that you can just feed into an ADC port on an AVR. The buttons can be directly attached to an AVR I/O port and software debounced or use a capacitor to debounce. Even the most sophisticated joysticks on the market still typically just use good old fasioned potentiometers so you can convert pretty much any joystick that exists

-Curiosity may have killed the cat
-But that's why they have nine lives

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The PC analog joysticks with DB15 male connectors are nothing more but around a 100k linear potentiometres on the X and Y axes. The potentiometres have +5V as the common wire and their resistance is minimum (~0 to 10 ohms?) in the upper-left corner, maximum (~100k or so,depends on the pot of course) at lower-right corner, and half of maximum at centre position. The joystick position (or resistance) was usually measured by charging a capacitor through the joystick potentiometer and determining the time how much it took for the capacitor to charge (a quad NE555 part called NE558). The button wires are just normally open buttons and connected to ground when pressed.

This method was used from since the first ISA joystick adapters to first PCI sound cards with joystick ports. Later on, more advanced sound cards had programmable treshold voltage for terminating the measurement, and was usually called speed compensation to get slower and faster PCs to get similar timing results with same joystick. Most advanced sound cards had joystick interfaces with A/D converters as a bonus, so the resistance could be directly measured with a voltage divider, but they were also compatible with the old way of measuring.

If perfect compatibility is not required, I'd suggest giving the joystick +5V and GND, pulling the X and Y axis pins down with 100k resistors, and measure the voltages with ADC pins. This may be non-linear, you have to check that yourself. Arranging the original way of capacitor charging will also be fine with just few IO pins, or you can use the analog comparator or get NE555/NE556/NE558 chips to get timed pulses.

Joystick buttons can be directly connected to AVR IO pins, either with external or internal pull-up.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Butterfly has a joystick :D

But seriously, look at: http://www.mindaugas.com/project... for some good info

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sceadwian wrote:
Joysticks use POT's, most of the other electronics inside you don't really need. Just gut all the internal electronics accepting for the stick pots and buttons and replaces with AVR circuitry. POT's typically have three terminals, you apply (something like) 5V to one end, and GND the other end and it acts as a voltage divider that you can just feed into an ADC port on an AVR. The buttons can be directly attached to an AVR I/O port and software debounced or use a capacitor to debounce. Even the most sophisticated joysticks on the market still typically just use good old fasioned potentiometers so you can convert pretty much any joystick that exists

I'm hoping to maintain all original functionality of the joystick though. So like I'm planning on making an AVR board that has a DB-15 connector on it so that I can just connect any ol' joystick to it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
The PC analog joysticks with DB15 male connectors are nothing more but around a 100k linear potentiometres on the X and Y axes. The potentiometres have +5V as the common wire and their resistance is minimum (~0 to 10 ohms?) in the upper-left corner, maximum (~100k or so,depends on the pot of course) at lower-right corner, and half of maximum at centre position. The joystick position (or resistance) was usually measured by charging a capacitor through the joystick potentiometer and determining the time how much it took for the capacitor to charge (a quad NE555 part called NE558). The button wires are just normally open buttons and connected to ground when pressed.

This method was used from since the first ISA joystick adapters to first PCI sound cards with joystick ports. Later on, more advanced sound cards had programmable treshold voltage for terminating the measurement, and was usually called speed compensation to get slower and faster PCs to get similar timing results with same joystick. Most advanced sound cards had joystick interfaces with A/D converters as a bonus, so the resistance could be directly measured with a voltage divider, but they were also compatible with the old way of measuring.

If perfect compatibility is not required, I'd suggest giving the joystick +5V and GND, pulling the X and Y axis pins down with 100k resistors, and measure the voltages with ADC pins. This may be non-linear, you have to check that yourself. Arranging the original way of capacitor charging will also be fine with just few IO pins, or you can use the analog comparator or get NE555/NE556/NE558 chips to get timed pulses.

Joystick buttons can be directly connected to AVR IO pins, either with external or internal pull-up.

- Jani


So I found this page: http://technick.net/public/code/... that has the pinout for them. I had assumed that the pots were acting as voltage dividers, but now it's clear that they aren't from looking at that page. So - surely there's a way to get a linear reading out of them? I think pulling down the x and y axis with resistors would get rid of linearity. It would also decrease accuracy, unless I'm forgetting something. I don't mind additional circuitry, as the size of this board won't matter one bit.

Also - so there's only 4 button pins. The joystick I want to use has ALOT of buttons. Certainly more than 4. Maybe a different signal is produced on those 4 button pins for each button? Like button 1 gives 0001, button 2 gives 0010, etc.

Lastly - on that page there's 4 different pot inputs listed on the pinout. My joystick is just a fairly normal joystick with the standard x and y directions, so I'm assuming those are the joystick 1 x and joystick 1 y signals. But it also has a throttle control which is on a pot, and a rotation control where you can rotate the actual stick thing. Maybe those are the joystick 2 x and joystick 2 y signals?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nleahcim wrote:

So I found this page: http://technick.net/public/code/... that has the pinout for them. I had assumed that the pots were acting as voltage dividers, but now it's clear that they aren't from looking at that page. So - surely there's a way to get a linear reading out of them? I think pulling down the x and y axis with resistors would get rid of linearity. It would also decrease accuracy, unless I'm forgetting something. I don't mind additional circuitry, as the size of this board won't matter one bit.

Also - so there's only 4 button pins. The joystick I want to use has ALOT of buttons. Certainly more than 4. Maybe a different signal is produced on those 4 button pins for each button? Like button 1 gives 0001, button 2 gives 0010, etc.

Lastly - on that page there's 4 different pot inputs listed on the pinout. My joystick is just a fairly normal joystick with the standard x and y directions, so I'm assuming those are the joystick 1 x and joystick 1 y signals. But it also has a throttle control which is on a pot, and a rotation control where you can rotate the actual stick thing. Maybe those are the joystick 2 x and joystick 2 y signals?

Good site you found. There is something on joysticks also at www.epanorama.net http://www.epanorama.net/documents/joystick/pc_joystick.html. You could test drive your joystick with a PC to see how all the buttons and axes work. Some joysticks are pure analog ones (max 4 axes and 4 buttons, some ThrustMaster joysticks use diodes with button lines to get nearly 16 buttons, some of them is a Point-Of-View (POV) hat, and the throttle is the third axis, joy2 x or y ). Some joysticks are digital, like Logitech Wingman Extreme Digital. It looks like an analog joystick at first, and it has selectable Wingman Analog and ThrustMaster modes, but with a specially timed triggering sequence it goes into digital mode, and it outputs all the buttons and axis states serially bit-banging the button lines to get 6 buttons, 9-way POV hat, throttle and of course X and Y axes.

So your mileage may vary. There are some Linux drivers which use the joysticks in digital mode, so if your joystick has one, you can replicate the digital mode and forget the analog mode. But then this will not work with normal analog joysticks.. And you still need some analog circuitry to generate the timing pulses to joystick MCU.

Try to make some kind of voltage divider yourself with the joystick axis pot as the variable resistance to VCC, then you can use the paper&pen (or excel/OOo calc) method to see if it is linear or not when resistance changes. Or just use the charging capacitor method.

- Jani

[woo, my 100th post][/url]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PC joysticks are variable resistors, not potentiometers. You write to port 0x200, it triggers 4 oneshots, and the R is variable. You hang in a tight loop reading port 0x200 and counting untill all 4 oneshots time out, then you have your x1 y1 x2 y2 joystick values. No a/d required. Just 4 oneshots.

Imagecraft compiler user