Introduction: Control Arduino Functions With a USB Controller, No Soldering Required- I Made It at TechShop
This is what I'll specifically be making in this instructable:
Pros: Easy to do with a low barrier to entry, cheap and there's no risk of damaging your controller.
Con: Because a computer is being used as an intermediary between the controller and the Arduino, as it's interpreting button presses as keystrokes which are fed into Processing, the computer is required; with this method you can't have a standalone Arduino and controller. If that's what you want then you'd likely need to alter the controller to plug directly into the Arduino.
Last note: I'll be specifically talking about the wired Xbox 360 controller and some of the weird little issues that can come up with it, but I don't see why this couldn't apply to any USB controller.
I made this project over at TechShop (http://techshop.ws/).
Step 1: Software/hardware
Computer and keyboard (USB keyboard and built-in laptop keyboard tested to work)
Xpadder 5.3 (see next step)
Step 2: Mapping Buttons With Xpadder
The first step is to download Xpadder, the program that maps controller button presses to keyboard strokes. There are other programs that do the same thing, such as Joy2Key, but this is the one I'm most familiar with. It's Windows only, and I don't know if there are any equivalent programs on Mac.
Xpadder 5.3 and below are freeware; anything later costs $10. This version can be downloaded here.
Plug in your USB controller, install Xpadder to a directory and open it. Xpadder may not work properly on a 64-bit system running Windows 7 or 8, but I've had success right-clicking Xpadder.exe, selecting Properties and running it in Vista compatibility mode. Xpadder should auto-detect your controller. To begin, select the small controller icon in the top left and choose New.
Now begins the mapping. Each area of the controller (sticks, buttons, triggers, etc.) are sectioned off into different tabs. Each needs to be enabled by checking the small box; after doing so Xpadder will prompt you to press a certain direction on the stick or dpad. The Buttons tab is even more straightforward, just press buttons and they'll appear on the screen. You can drag the icons around, which I highly recommend to stay organized. Remember that when mapping buttons, on the Xbox 360 controller clicking the sticks in also counts as separate buttons. Once you're done mapping everything, select Finish.
This will bring you back to the main Xpadder screen. By default Xpadder will have mapped all of the buttons to various keys on the keyboard, which should be fine. Save this as a profile by clicking on the controller icon again and selecting Save As. I've attached my profile file, which is just dropped in the main Xpadder folder.
Step 3: Processing/Arduino Programming
This part's fairly straightforward. In the Processing code you can see that I've assigned each keyboard key a numerical value. When that key is pressed it'll be sent over to the Arduino. On the Arduino side of things, each value has a function that will be performed while it is active; here, I've mapped every value to display a different color on the RGB LED. For your own project you can of course replace that code with anything else you might have in mind.
I won't copy/paste the code here because of how long it is, so I've attached both files. rgbalphabet.zip is the Processing file, and xboxrgb.zip is the Arduino file.
Step 4: Put It All Together and Run It!
One last note about this process and using an Xbox 360 controller. For this to work, the Processing java popup that opens when the script is run has to be the selected window (the one on top). However, when you press the Guide button in the center of the controller it'll open a Windows popup on the screen displaying the controller's status and take over as the featured window. The best fix I found was to simply open Add/Remove Programs and uninstall "Microsoft Xbox 360 Controller Accessories." This only affects the (really quite useless) popup message specifically and won't touch the drivers, so the controller will still function just fine when playing a game.
Here is an example of how this sort of thing can be used. This is a project that I made and was the reason I went through this whole process in the first place:
We have a be nice policy.
Please be positive and constructive.