loading
Picture of USB Game Pad With Tilt-accelerometer Mouse
 
Make a game pad with an accelerometer inside!

This project tutorial will show you how you can convert a console game pad into a USB keyboard mouse for playing games on your PC. The USB game pad can be used with nearly any software, such as a MAME emulator, game, simulation software, or for custom user interfaces.

We'll start by turning the buttons of the game pad into keyboard buttons, so that pressing 'up' is converted into the 'U' key, for example. The firmware is easily adaptable, so you can adjust it for whatever software it will be used with.

Then we'll make the project more interesting by adding an accelerometer. This will allow the game pad to be used as a mouse by tilting it!

Credits

This tutorial including the original code and Portal video is by Devlin Thyne! Rock!



 
Remove these adsRemove these ads by Signing Up

Step 1: What You'll Need...

Picture of What You'll Need...

 
You'll need the following in order to build the project:

  • Game pad - We'll be using an SNES controller
  • Teensy - This is a very small microcontroller board that can act as a keyboard/mouse
  • Triple-axis accellerometer - We'll be using the nice ADXL335 on a breakout board. You can skip this if you're not planning to add in the mouse capability
  • USB cable with mini-b connector - to attach to the Teensy for plugging into a computer!
  • Ribbon cable - for all the soldering connections. Rainbow cable is the easiest to work with as its color coded

If you want to build the entire project, we have a project pack in the shop with all the parts listed above!

You'll also need some basic hand tools such as screwdrivers, wire strippers, soldering iron, solder, diagonal cutters, vise or third hand tool, etc.

All the code is on GitHub, including some extra sketches we've written so be sure to look there!

Step 2: Disassemble the SNES Controller

Picture of Disassemble the SNES Controller
snesopen.jpg
snesopened.jpg
pcbout_t.jpg
groundtrace_t.jpg
snes.png
 
We'll begin by disassembling the SNES controller. There are 5 small phillips screws on the back [see image 2a]

Once you lift the back off, you can remove the PCB. Be careful as there are tiny wires for the 'side' buttons so just make sure those pieces come out cleanly [see image 2b].

Each button is made of 3 parts - there's the plastic part that you press, beneath that is the elastomer which is a rubber molded piece with a conductive bit that goes underneath the plastic part, and finally on the PCB there are two interdigitated and exposed traces. When the user presses the plastic button, it pushes down on the elastomer which then pushes the conductive rubber onto both traces, shorting them.

There is also a black blob in the middle. This blob is a chip that takes all the button inputs and then converts it into the way that the SNES wants to hear. That's all fine, but we don't want to use the blob because we are going to make our own custom chip software. (Note that it would be pretty easy to make the Teensy 'talk' right to the blob using the SNES protocol but then you wouldn't be able to adapt this tutorial to other controllers, for that reason we're going to do it the 'hard way')

The question is now how can we listen to all the buttons?

Well, luckily, almost all game pads are going to use a similar method for arranging the buttons. If you note carefully at the PCB, you'll see that each button is made of two traces, but that all of the buttons share one trace together [image 2c].

This is the common (ground) trace. If we were to make a schematic, it would look kinda like image 2d.

Note that this is really just a symbolic schematic, the ground wire doesn't necessarily connect on the side that's indicated, we're just showing how all the buttons have a common ground pin!

OK now this is straight forward, if you are not sure how to read buttons with a microcontroller, we have a nice tutorial you might want to check out (in fact, we really suggest it as we'll be referring to concepts in that tutorial) Basically each button connects to an input of the microcontroller. We'll need a pull-up resistor, but luckily we can set the microcontroller's internal pullups (so we don't have to solder in 12 10K resistors!) Then the microcontroller can listen on each pin for a button press and when it is received, generate a keypress event.



Step 3: Introducing the Teensy with HID

Picture of Introducing the Teensy with HID
teensyparts.jpg
 
So you may be wondering "heck, I should just grab an Arduino!" But a 'proper' Arduino can't do what we want, which is to appear as a keyboard. When you plug in an Arduino into your USB port, it shows up as a Serial device, which is fantastic for debugging or for interfacing to Processing. To listen to a Serial device, you need to open up Hyperterm or Zterm or the Arduino IDE's serial monitor. However, it does not act as actual keyboard where what it outputs goes to Microsoft Word or a video game.

For that, we need a different kind of chip, a chip that is USB native! USB native chips can act as USB serial ports, but they can also act as MIDI devices, keyboards, mice, audio devices, joysticks, etc. Nearly anything! A nice chip that does all this is the ATmega32U4 (the U is for usb!) and the Teensy is basically this chip, a USB connector, button and some other necessary things. Its very tiny (thus the name) and has a fantastic programming interface that is basically the Arduino + a helper, it runs under Mac, Linux or Windows.

Step 4: Stop! It's solder time!

 
OK we're basically ready to go. The plan is to solder a single Ground wire to the common ground for all the buttons, then solder a separate wire to each button (the not-ground side). The ground connects to the Teensy ground, the button wires connect to all the solder pads down the side. Then we'll write the code that listens to the button presses and converts them

Cut off a strip of ribbon cable, about 4" long. Use diagonal cutters or fingernails to carefully nip and 'rip' the individual wires apart about 1" and then strip the ends and tin them with solder [see image 4a]. Do this for both sides.

To connect to ground, we'll expose a little copper in the top left corner, this way we don't have the wire running underneath the elastomer [see images 4b and 4c].

Solder the Black wire to the ground plane, we brought the wire through a hole [see images 4d and 4e].

OK lets solder to the first button. The key is to remember to NOT solder to the same common pad but to the opposite pad! Solder the white wire to the 'up' button. There's almost always a hole you can feed the wire through! [see image 4f]

Solder the gray wire to the Right pad, the purple wire to the Down pad and the blue wire to the Left pad [see image 4g]

Then the orange wire goes to the L1 button, the yellow goes to Start and the green to Select [see images 4h and 4i].

I didn't end up using the Red or Brown wires so I tore those off the ribbon. Now cut another piece the same size but with only the white, gray, purple, blue and green wires.

Connect white to B, gray to A, purple to X, blue to Y and green to R1 [see images 4j and 4k].

If you haven't yet, now is a good time to desolder the SNES connector cable. We wont have space for it so just pull each wire as you heat the solder joint (or just cut them short, either way) [see image 4m]

OK! Now all the buttons are wired up, its time to attach them to the Teensy. Place the Teensy in a vise or carefully use a 'third hand' to hold it (grab by the USB connector)

First, solder the black wire to the ground pin [see image 4n].

Next start soldering in all the ribbon cable wires, one after the other, without skipping any holes [see image 4p].

After the first ribbon cable, go to the second piece, starting with the white wire. The last green wire goes next to the blue one on the 'short' side [see images 4q and 4r].

Now we are ready to upload code to the Teensy and test out our work!

 


Step 5: Installing Teensyduino

The Teensy uses the USB connection for programing, so we don't need a separate AVR programmer. We will use the Teensyduino IDE, which is a patch to the Arduino IDE.

If you don't have it yet, download & install Arduino v18

Next, download the Teensyduino installer for your OS and run it, patching the Arduino IDE

Finally, be sure to also grab Teensyloader which is a helper that talks to the Teensy for you

Step 6: One button test

Picture of One button test
prebutton.gif
postbutton.gif
foundHID.gif
keymouse.gif
teensydevmanager.gif


We'll start with the 'one button test' sketch, which will only listen for the 'Up' D-Pad button and output the letter 'u'

Understanding this code now will make it a lot easier to understand the later sketches that are much more complex!

You can grab this code (which may be updated!) at github

Now we'll upload this sketch to the Teensy. Make a new sketch and copy the code in. Select the Teensy 2.0 (USB Keyboard/Mouse) item from the Board menu [see image 6a].

Make sure the Loader is running, if you see this [see image 6b]

Press the tiny button to start the bootloader, so that it looks like this [see image 6c]

Upload the sketch! You should see it sucessfully program the Teensy, and reboot. The OS will then alert you that it found an HID device [see images 6d and 6e].

And the device manager will now have an extra Keyboard and Mouse called "HID Keyboard Device" and "HID-compliant mouse" [see image 6f].

You should now be able to open up a text editor and carefully push the 'up' D-pad to generate 'u's!

Step 7: All button test

Picture of All button test
 
Next we can upload the sketch that uses all the buttons so you can test each connection. Its much longer so you'll have to download it from github

You should test all the buttons, to make sure they all output characters.

This code is more involved since it has to listen to 12 buttons. You can see at the top where we define an array of all the buttons, and then the keys that correspond to the presses. In this case, we're using a simple one-to-one correspondence for key presses, such as Up being 'u'. To adapt this code to allow for things like "Alt-F3" would be a little more complex.



Step 8: Adding the Mouse

Picture of Adding the Mouse
adxlwires_t.jpg
adxlpower_t.jpg
adxlxyz.jpg
 

Now we will add in the accelerometer to create a tilt-activated mouse. Nearly any accelerometer will do, but the easiest to use is an analog output one. The ADXL335 will work great. First we will power the chip by providing 3.3V (not 5.0V) and ground from the Teensy, then connect the three analog outputs (X Y and Z) to three analog inputs. Finally, we will add Mouse'ing code to the sketch so that Mouse movement events are sent when the controller is tilted.

Cut a piece of ribbon cable down, we'll use Brown for Ground, Red for +3V, then Orange Yellow and Green for X Y and Z respectively [see image 8a].

We tore the brown wire off so that it wouldn't be twisted [see image 8b].

The ADXL335 requires 3V power, so don't connect it to VCC (5V) instead, we'll use the 3V that the teensy provides - it uses that voltage for the USB communication, you can't draw more than maybe 20-40mA which is plenty for this but not enough for perhaps a bunch of LEDs! Brown connects to the second GND pin [see image 8c].

Next connect X, Y, and Z to F5, F4, and F1 (don't use F0!) [see image 8d].

You should now try out the next sketch, teensySNES_test2.pde which will move the mouse as you tilt the controller.

Step 9: Closing it up

Picture of Closing it up
sticky1_t.jpg
adxlstick.jpg
cabletwist_t.jpg
resethole_t.jpg
done_t.jpg

 
Now that the mouse and keyboard are working, we can close up the game pad. This is actually the toughest part of the project, as the enclosure has plastic standoffs that are in the way.

One thing that will help is 'deribboning' the ribbon cable, so that it is easy to push around the wires [see image 9a].

Use sticky foam tape or hot glue to place the Teensy right at the top [see image 9b].

Likewise, align the accelerometer so that it is as shown (otherwise you may have some flipped axes. You should put it near the middle but we didn't see any difference being in this location [see image 9c].

Finally, twist the USB cable so that it goes through the strain relief posts. If this makes it really tough to close you can probably skip it and just be careful not to yank! [see image 9d]

As you close the case, use tweezers to poke the wires around inside so that they do not interfere with the standoffs.

We wanted to make sure we could update the code without going through the disassembly process, so we drilled a hole in the back right over where the button is, then used a paper clip to push the tiny button [see image 9e]. You can also just solder two wires to GND and RST and bring these out of the case, when shorted it will start the bootloader.

You're done! Enjoy your new toy, and modify the sketch if you need to change the key commands or mouse movements.

yolivas3 years ago
I want to do this to a GameCube remote, so how do I connect the analog sticks?
WaqarA4 yolivas3 months ago

You solder VCC to the VCC pin and the UP,Down left and right to the digital pins, then you open the Arduino IDE and program it using the code that adafruit has on github as something to start with.

Usablerain2 years ago
Would this work with the Portable Raspberry Pi Emulation Machine (http://www.instructables.com/id/Portable-Raspberry-Pi-Emulation-Machine/#intro)?
OK. I figured this one out. This menu option is no longer there as pictured, but what you should do is to select your teensy board, usually a teensy 2.0 and the go to another sub-menu, also on the Tools menu called, USB Type ... Select Keyboard + Mouse from this menu, and then you can proceed with the rest of these steps.
I have tried to follow these instructions carefully, but I don't see an option for the Teensy (USBKeyboard/Mouse) on my board menu. I do see teensy 2.0 and teensy++(2.0). What is the most likely the cause of that?
snehal09095 years ago
why do all this when you can buy a really good quality NEW usb gamepad for $20.
you shut your mouth!!!
Can you actually? I haven't seen a single USB gamepad with a decent D-pad. They all have the horrible design (where it's hard to deliver a 'pure' up/down/right/left because they wobble back and forth between two switches at once) because the good designs are still under nintendo or sony patents.
What would you learn from just buying one?
 Its more fun to build than to buy! :)
it is done, because it can be done.  It is recycling something  that some of us have sitting around in a closet without any use anymore because we dont play Super Nintendo anymore.
=( why aren't you playing your Super Nintendo anymore? It's lonely and it needs love.
Good easy project for people like me that's learning about electronic modification, too.   :3
tp1l4 years ago
One option if you wanted to do this one the cheap would be to hack the buttons into the inputs of a USB keyboard. Just break open a keyboard and trace out eh leads on the membrane from all of the keys you need, and wire them up directly to the gamepad buttons.

The big downside is that it would likely involve a care mod to fit the keyboard PCB in with the rest, or I suppose you could run all of the switch leads in a thicker cable to the keybaord PCB in a separate housing.

Whether or not this is worthwhile is probably a factor of your budget. It'll add some hassle but save $20 for the Teensy.
Icalasari4 years ago
...This will make playing gameboy games a LOT easier
Foaly74 years ago
I think that this would be even better wireless, maybe bluetooth that plugs into the computer on one end, for people who have XBMC computers attached to their TVs.
mcrjig5 years ago
could you do this with a N64 controller?
Undead mcrjig5 years ago
Thats what I wanna know too!
Check out http://raphnet.net/electronique/gc_n64_usb/index_en.php
andreq5 years ago
Nice instructable !

I've done the same thing some time ago with a "full" DIY version :

You have 2 possibilities :

1 - raphnet.net/electronique/snes_nes_usb/index_en.php
he use an atmega 8 with a xtal for the pad-usb conversion. It's a nice idea, but the overall size of the project (if you do it without a PCB) is a tad big to fit inside the pad.

2 - translate.google.ca/translate
He use a small Attiny 45 with internal osc for the pad-usb conversion. I've used this method for my own pad. It fit quite easily in a SNES gamepad. I didn't have any Attiny45 on hand, but I had some Attiny25... I've managed to make the code smaller and include the auto usb calibration. It was quite a tight fit in the 2k memory!  I'll try to post my modified files for you to enjoy.

I might even post an instructable if I have some spare time.

andreq andreq5 years ago
Here's the second link :

http://translate.google.ca/translate?hl=fr&langpair=de|en&u=http://hobbyelektronik.org/w/index.php/SNES-Joypad

ai3sixers5 years ago
Hi, cheers for an excellent Instructable. Was wondering, can this be easily applied to a Sega Mega Drive 6 button gamepad?
epizeuxis5 years ago
Looks great! I'll have to try this some time.
samirsky5 years ago
 Thanks!  Always enjoy your tutorials.