This project will show you how to create a real USB game pad using a Wii Classic Controller.

Through the steps, you will learn about:
  • How USB works
  • How I2C works
  • How to read data from the Wii Classic Controller
Some of these pre-requisite skills would be nice
  • General electronics
  • AVR programming
The code will be based on V-USB, and the circuit will be based on a implementation V-USB example circuitry called USnooBie.

The entire project is provided as a ZIP file download below. Also see below for a flowchart of how the code will work.

Step 1: Using the AVR With V-USB

For the microcontroller, we'll be using a ATmega328P. This microcontroller has enough memory resources and a built-in TWI/I2C peripheral to accomplish our goals. However, it does not have built-in USB, which is a problem that we are going to solve using V-USB.
"V-USB is a software-only implementation of a low-speed USB device for Atmel’s AVR® microcontrollers, making it possible to build USB hardware with almost any AVR® microcontroller, not requiring any additional chip."

- V-USB official website

V-USB uses a set of hardware and some very special assembly programming techniques to bit-bang the non-return-to-zero (NRZ) binary code that USB uses to communicate. The files provided by V-USB will be compiled into our program in order to create a USB device with our ATmega328P

Please visit the download section of V-USB's website to obtain a copy of the latest version. In my project source code, it's already included.

To compile V-USB into your project...

  1. Make sure you've defined the processor and clock speed correctly (V-USB only supports certain clock speeds)
  2. Copy the folder "usbdrv" from the downloaded package into your project folder
  3. In your project manager or makefile, include "usbdrv.c" and "usbdrvasm.S", such that the object file that's generated will become linked into your project
  4. Inside the folder "usbdrv", there is a "usbconfig-prototype.h", copy that file into your main project directory, and rename it to "usbconfig.h"
  5. Edit "usbconfig.h", this will be explained in detail later
  6. Use "#include" statements to include "usbconfig.h" and then "usbdrv/usbdrv.h"
  7. Make sure that "usbdrv/usbdrv.h" is able to find "usbconfig.h", if it's not able to, use the use "-I" to your makefile or edit "usbdrv/usbdrv.h" to change the file path to "usbconfig.h" (to "../usbconfig.h")
Then your project must implement the some functions...
  • You must initialize V-USB, and then enable interrupts in the AVR
  • It's almost a standard practice to fake disconnect, wait a few milliseconds, and reconnect to the computer, during starting the code. This makes sure your device and computer are in a "reset" state to start off.
  • A request handler function must be implemented, even if you don't perform real actions in it, you must implement it yourself. Look for "usbFunctionSetup" later.
    • In our example, we need to use this function to handle two special requests, you'll see it later
  • The gamepad is a HID device, a USB HID Report Descriptor must be written and stored in your code
More Reading:
Now do you think it's possible to do this the other way around? Like spoof the classic controller?<br>
Yes, perfectly possible, I have done this already but I re-created a Rock Band drum set<br><br>If you want to see it, go here http://frank.circleofcurrent.com/index.php?page=wii_drum
Oh by the way, the Wii version of Guitar Hero World Tour comes with a drum set that you plug into the Wiimote, which operates very similarly to a Classic Controller (the encryption is the same, the difference is one byte in the ID field and a slightly different data packet format). The library I created allows for any Wiimote extensions to be created. I use a drum as my best example of its usage.
Hello, frank <br>amazing work done by you especially VBUS and USB HID details on your site but i need little help , as i can see that you have attached saleae logic analyzer to analyze the usb bytes i was also trying to do tht but my logic analyzer didnt give me any good results most of them were errors <br>my connection was something like this <br><br>keyboard USB PLUG ----(saleae logic analyzer in parallel with gnd common and D- and D+ connected to 0 and 1 channel ) ----- PC USB port <br><br>but i was aunable to figure about why it didnt work so please help me with its connection so i can implement USB protocol in project
<p>Hi, thanks for the tutorial.</p><p>I'm having trouble in here: </p><p>twi_writeTo(WIIEXT_TWI_ADDR,twiBuffer,7,1);</p><p>It seems program cannot get past this line due to waiting for writing to finish (setting last parameter to 0 lets program continue, however, no communication with classic controller seems to be happening).</p><p>WIIEXT_TWI_ADDR is defined as 0x52</p><p>I'm using Atmel Studio 6.2 to compile and a clone Classic Controller, any idea on what i can try?</p>
<p>You've encoded the analog positions as signed ints from -127 to 127... this is against spec and very unconventional. I'd be interested in hearing if people have had difficulties with this report descriptor configuration on some platforms, as this may be the cause. The spec states that analogs should range from 0 to 255, with 127 as a neutral position. I've checked the report descriptors of several commercial gamepads (made by Microsoft, Logitech and Hori, and with vintages ranging from 2005 to 2012) using USBLyzer, and confirmed that this standard is respected in all cases (though the wired xbox360 actually uses 256, instead of 255 like all the others).<br><br>See:<br><a href="http://www.usb.org/developers/hidpage/Hut1_12v2.pdf" rel="nofollow">http://www.usb.org/developers/hidpage/Hut1_12v2.pd...</a></p>
Why are the gamepad sticks absolute while a mouse is relative? If I press up on my gamepad, surely I am moving up relative to my current position? Pressing up does not (alone) define my position. <br> <br>Thanks for the tutorial :-)
Hello sir ,I am using avrstudio4 for compiling your HID gamepad code and after compiling i am getting error message : <br>dep/usbdrv.c:8: *** target pattern contains no `%'. Stop. <br>sir please help me ,this is my final year project. <br>THANKING YOU IN ANTICIPATION.
Is it possible to remove the middle man and have a controller port coming out of the PC also will it work on a hackintoshi i am a noob when it comes to programing also a noob when it comes to computer hardware?
You must have the &quot;middle man&quot; if you want to use the Wii Classic Controller
im wondering if you know if a usb controll pad can be converted to plug into a wii remote? i have a usb arcade stick and would like to make it wirless by plugging it into a wiimote. is there a way of cutting off the nunchuk plug and wire it up to my arcade stick? <br> <br>thanks
kind of hard, I know how to do it, but is it worth the effort? how skilled are you? what kind of equipment do you have?<br><br>basically you need a microcontroller that can perform USB host duties, and also I2C slave duties. I have already created the code for the I2C stuff. The USB host stuff can either be LUFA if you are using a AT90USB1287 or you can use a &quot;USB host shield&quot; or similar. Or you can dive into ARM but then I don't have the code for it.
Hey! i love your project! but one question... do you think you can compile this on attyin85? similar to the http://hobbyelektronik.org/w/index.php?title=SNES-Joypad
It'll need some major changes. I don't think the ATtiny has dedicated I2C so that has to be changed to bit-banging. It is certainly possible.
wow thats great! i recently finished a nes to usb controller and i loved it. but i would of loved to be able to use a classic controller. But thus im not a avr programer so i dont know much. just enough to mess around a bit with the code.<br><br>but great tutorial! loved it! hopefully one day i can implement this on a attiny85.
Thank you for this project! <br> <br>Not because I've actually used it&hellip; But I copy-pasted this HID Descriptor into my project (that has a quite similar HID with keyboard+mouse), and found that your HID did work, while mine didn't. <br> <br>4 hours later, I finally found the bug in my project. I had written 0x0f where should have been 0x10, somewhere in the middle of my HID descriptor. <br> <br>So, thank you to help me find the typo in my code! :-) <br>I guess you never thought this intructable would be useful for that! :-P
You really put a lot of work into this instructable. Great work! <br><br>I have a question in regards to the format of your instructable. How did you get those dotted borders around your code? It makes the instructable look so neat and orderly.
In the editor, press &quot;view source&quot; to edit your Instructable in HTML (I think this is a &quot;Pro&quot; feature)<br><br><br>The bordered code is done within tags, but with a style attribute that specifies the border style<br><br><br>http://www.w3schools.com/TAGS/tag_pre.asp<br><br>http://www.w3schools.com/css/css_border.asp

About This Instructable




Bio: I am an electrical engineer. I graduated from U of Waterloo. I used to work for Adafruit Industries as an EE. Now I work for ... More »
More by frank26080115:LED Pocket Watch Easy Cord Wrapping Around Power Bricks Using SMD Components on Breadboards 
Add instructable to: