USB Game Pad With Tilt-accelerometer Mouse using an Arduino
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!
Step 1: 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!
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
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
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
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.
For more detail: USB Game Pad With Tilt-accelerometer Mouse using an Arduino
We recommend EasyEDA for electronic circuit design.
From Schematic Drawing to PCB Production, Just Need One Tool
Cheap PCB Prototype: 10 pcs 2 layers only $10, quick delivery, 100% E-test
This Post / Project can also be found using search terms:
- gamepad circuit