<< Return to Projects Page

Teensy 2.0 Simple Gamepad

Open Source Code

The Teensy 2.0 Simple Gamepad implements a simple USB gamepad with up/down/left/right and a configurable number of buttons (between 1 and 20). It is designed to run on the Teensy 2.0 board.

This code was designed to provide a working gamepad with customizable USB Manufacturer Name, Product Name, and Serial Number that requires minimal changes to the code. It is designed so that even someone with extremely minimal C coding experience can use the code to create a USB gamepad using the Teensy 2.0.

Download Source Files
 


Usage and Notes

To use the source code, you must first have a working Teensy 2.0 C development environment. This can be setup by following the instructions on the Teensy website, then you simply run make in the source directory after you configure your gamepad code.

To configure the gamepad code, all you need to do is edit the settings found in simple_gamepad_config.h. Follow the specific instructions in there. You will need to set the USB Manufacturer name, Product name, Product ID, and Serial Number. The Manufacturer ID is defaulted to the ID used in all the Teensy examples. Then, you simply decide the number of buttons your gamepad will have, and also there's an option if you are using your own external pull-up resistors. Any Teensy pins not used as buttons will be automatically configured as outputs, but you can also use them for other purporses if you want to modify the code. Then build it, and you will have a USB gamepad with up/down/left/right, plus the number of buttons you specified. The details about which pins map to which buttons are laid out in simple_gamepad_config.h.

This gamepad code was created when I could not find other solutions to create multiple gamepads with specific Manufacturer and Product names, as well as requiring unique serial numbers for each gamepad. It is used for my HTPC inside an original NES case project.


Credits

The following sources were used as reference/inspiration:
 
Teensy examples: http://www.pjrc.com/teensy/usb_serial.html
SNES USB Gamepad: http://www.slashdev.ca/2011/10/20/snes-usb-gamepad/
USB Reference: http://www.frank-zhao.com/index.php?page=hid_tutorial_1 (Old link is dead: http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/)
USB Reference: http://www.beyondlogic.org/usbnutshell/usb5.shtml


Contact

This code is open source, can be used for any purpose, and requires no attribution to me other than in the license. However, I would love to hear how you have used my code in your project!

To share your project with me, or if you have any questions regarding the code, please Contact Me.


License

Teensy Simple Gamepad
A Gamepad device with one 2-axis D-pad and 1 or more buttons
Copyright (C) 2013 Robert Byam, robertbyam.com

Derived from keyboard and serial examples for Teensy USB Development Board
http://www.pjrc.com/teensy/usb_keyboard.html
http://www.pjrc.com/teensy/usb_serial.html
Copyright (c) 2008 PJRC.COM, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.