USB Gaming joystick to control arduino

I'm setting out on a project to build an arduino controlled tower gun for an airsoft battle car.

The setup will be fairly simple: two DC motors that control the x and y axis through gears, electrical control of firing, and a backing camera for aiming.

Now, I would love to manage the control of the motors and firing through an old school pc gaming joystick, one like this:

http://geoo.gl/yscIQJ

How would one go about translating the joystick signals to arduino output on x and y?

I am an arduino noob, so be gentle. I have a mega and a Leonardo at my disposal. Can easily get a Due if needed.

The simplest setup would be to use servos with the joystick like used in cam pan/tilt setups.

The gun that I will be controlling is really heavy, and will need to be turned through gears. Since I want it to be able to sway 360 degrees on the x axis, and the speed to be easily varied, servos are just not that well suited.

But the mechanics of it is not really what I wonder about, I've got a pretty good idea about how to set that up.

I'm wondering about the I/O of it all: how to interpret the signals from the joystick, what libraries to use or write, and what code to implement it in.

Mixe: Now, I would love to manage the control of the motors and firing through an old school pc gaming joystick, one like this:

http://geoo.gl/yscIQJ

How would one go about translating the joystick signals to arduino output on x and y?

That link doesn't work for me.

There are zillions of joysticks which are easy to use with the Arduino and lots of joysticks which would be hard to use.

I posted some code in this post which makes it pretty easy to control servos with a joystick. It would be easy to expand the program to use six (or as many ADC inputs the Arduino has).

I like Wii Nunchucks as controllers.

I also like this joystick.

|473x500

USB joysticks intended to be used with a PC would not be easy to use with an Arduino. IMO, you're much better off using a joystick which you have access to the pots or to use an older game controller (there are lots which can easily be used with an Arduino).

I'm uploading a couple videos showing how my joystick/servo control code works. I think it works well. This video shows the joystick controlling the servos' position. This video shows the joystick controlling the servos' speed.

Mixe: The gun that I will be controlling is really heavy, and will need to be turned through gears. Since I want it to be able to sway 360 degrees on the x axis, and the speed to be easily varied, servos are just not that well suited.

What do you plan to use for position feedback? In order to accurately control the speed of the motors you really need some sort of encoder.

Pololu sells nice motors with encoders. There also sells boards which can be used to convert DC motors to servo type control.

DuaneDegn: I posted some code in this post which makes it pretty easy to control servos with a joystick. It would be easy to expand the program to use six (or as many ADC inputs the Arduino has).

I also like this joystick.

|473x500

I'm uploading a couple videos showing how my joystick/servo control code works. I think it works well. This video shows the joystick controlling the servos' position. This video shows the joystick controlling the servos' speed.

That is EXACTLY what I want to achieve, just on a bigger scale. And that joystick is also perfect! Thank you!

I am completely new to encoders and don't even understand the basics of them yet. I thought that since I have visual feedback of the guns movement that would be sufficient. And then just vary the current to the motor to vary speed?

I'm also waiting for a L293D motor shield to control the DC: s through. Would that work you think?

The gun on top will be like this:

m249 airsoft

And the motors controlling the sway I thought would be these:

TAKANAWA 555 Metal Gear Motor 12V-24V DC Gear Motor https://bnc.lt/m/ZcDdR3kjCp

I hope these links work.

The alternative is of course to use servos modified for continuous run. But you can't easily vary the speed of those, right?

Mixe: The alternative is of course to use servos modified for continuous run. But you can't easily vary the speed of those, right?

One of the useful things about continuous rotation servos is you have both rotation speed and rotation direction control. I don't think a L293D motor H-bridge will work well with larger motors you may want to use.

Oh? And how do you vary the speed of continuous servos? Also, what kind of motor shield would be sufficient for the kind of DC motors I linked?

zoomkat:
I don’t think a L293D motor H-bridge will work well with larger motors you may want to use.

+1

Pololu sells a bunch of nice h-bridges.

Parallax has their HB-25 motor controllers which are really nice but pricy.

I’m not sure if they would safely power the motors you plan to use but I like Pololu’s MC33926 h-bridge. If you get two MC33926 h-bridges, you’re better off getting getting two separate PCBs than purchasing their dual chip driver. The dual chip driver board has few control options (and important options IMO) than the single chip boards.

Mixe:
Oh? And how do you vary the speed of continuous servos? Also, what kind of motor shield would be sufficient for the kind of DC motors I linked?

It might be worth while for you to do google and youtube searches for turret gun, sentry gun, and similar to see what others have built. With a heavy gun, building a low friction carefully balanced pan/tilt platform will be needed. Large standard/sail servos might still be an option with a well designed platform.

That is good advice. I have googled pretty intensively and extensively beforehand, browsed through the entire Sentry Gun Project and 3-4 other ones. I have also tested different mechanical solutions and came up with the material I found worked best while still beeing affordable. Like I wrote, I am pretty sure about the mechanical solution, provided it's feasible from a digital and electronic viewpoint.

I have a large, ball bearing supported base with very little rotational friction and a tripod head with smooth tilt on top of that. Even so, at least the tilt will still have to be supported by a stronger, larger motor and gears.

Pololu is also kind of pricey for me, since the postage to Sweden doubles the cost or more. I'm in no hurry, so I very much favor Chinese solutions with slow but free postage. I'll take a stroll down eBay lane with your advice :)

So I went ahead and bought the joystick you tipped me about, DuaneDegn. It's perfect, beautiful and very cheap. Seems like really good quality, too.

Unfortunately, it comes with the usual drawback of cheap Chinese stuff: no instructions. The visible pots are straightforward enough, but the Z- axis and the button are connected through wires. I have one red, one black, one white and two blue ones coming out of the joystick. Do you know which one goes where?

I can disassemble it and see where they go, or just try them out by applying voltage randomly, but I'm afraid to damage it. It takes too long to get a new. So if you know, that would be great!

Mixe:
Unfortunately, it comes with the usual drawback of cheap Chinese stuff: no instructions. The visible pots are straightforward enough, but the Z- axis and the button are connected through wires. I have one red, one black, one white and two blue ones coming out of the joystick. Do you know which one goes where?

Three of the wires are connected to the z-axis pot. You can use an ohmmeter to find the wiper.

On my joystick the black wire is the z-axis wiper.

The red wire was the pot’s Vdd.

The blue wire which measures 5k (of whatever value the pot is) between itself and the read wire is the pot’s ground wire.

The blue wire with infinite resistance between it and the red wire is the button wire. When the button is pressed, the two blue wires are shorted together the blue button wire is shorted with the white wire.

I added a six pin connector to my joystick.

Joystick150426g.jpg

I joined the three Vdd pins together and connected these to one of the six pins. The grounds were all connected to a second pin. The three wiper each had a pin and the button wire was connected to the last pin.

Joystick150426f.jpg

The ground and Vdd positions on the two lower pots are arbitrary. I wired them in a way which would give larger analog values as I moved the joystick to the right and up.

The button pin is pulled high by the Arduino and when the button is pressed, the button wire gets connected to ground. This makes it an active low button.

It would certainly be possible to wire the button so it’s active high. This would require swapping the Vdd and ground lines to the z-axis pot and using a pull-down resistor on the button line.

Excellent! Thank you so much. However, this still leaves me with the mysterious white wire. I wonder where that one goes?

Mixe: Excellent! Thank you so much. However, this still leaves me with the mysterious white wire. I wonder where that one goes?

The white is ground (if you're using the button active low).

I just realized I have an error in my earlier reply. I'll fix it.

Edit: I fixed the earlier post. The white wire gets shorted to the blue button wire when the button is pressed. If the button is to be active low, then the wire wire is ground. If the button is active high, then the white wire is Vdd.

Aha! Yes, I sorta stumbled on that sentence but thought I would get back to it and give it some effort later :). This makes everything crystal clear, thank you!

What I’m about to try now is making the x- axis control the speed of a DC motor for rotation, and have the Y axis control the position of a servo for the tilt. The (paintball) gun turret I’m building will need to be able to swing 360 degrees in both directions pretty fast, but will not need very much range in the tilt. It will be sitting on top of a car.

I would also love to make the z-axis control the zoom of the camera. My next mission will be to find the hardware for this. If anyone has any ideas …