Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.

Wiimote Extension Library
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Wiimote Extension Library

by frank26080115 on Sun Mar 15, 2009 2:38 am

Wiimote Extension Library for AVR Microcontroller

This is a library that gives an AVR microcontroller the ability to act as a Wiimote extension controller (Nunchuk, Classic Controller, Guitar Hero 3 controller, Guitar Hero World Tour guitar controller, Guitar Hero World Tour drum controller, etc). The library has two parts: the I2C slave device and Wiimote protocol handling. It can be used with AVR-GCC, and it is possible to adapt it to work with Arduino if you know how to include the files into your sketch properly.

wiimote.c and wiimote.h handles the interface between the application software and the I2C registers, it also handles the encryption of the data sent to the Wiimote. The encryption look-up tables are in wm_crypto.h . Some functions are used to make the microcontroller a register based I2C slave device. It has 256 registers in an array, these registers are written to and read by the Wiimote via the I2C bus using a fairly standard method.

Example of Use DIY Rock Band 2 Drum Controller

Using the Library

You need to connect the Wiimote's extension port to your microcontroller's I2C bus. There is also one pin on the extension port that is used to detect whether or not something is connected, this should be connected to Vcc, or if you want to control this detection, connect it to an I/O pin.

The pin-out of the extension port is shown below, the order from left to right is the same order looking at the back of the Wiimote.

|| Ground || No Connection || SCL ||
|| SDA || Device Detect || Vcc (3.3V) ||

Define your hardware connections in wiimote.h like so:

Code: Select all | TOGGLE FULL SIZE
#define twi_port PORTC
#define twi_ddr DDRC
#define twi_scl_pin 5
#define twi_sda_pin 4
#define dev_detect_port PORTD
#define dev_detect_ddr DDRD
#define dev_detect_pin 4

This depends on the chip you use and your circuit.

Calling wm_init will start up the I2C hardware and prepare the AVR for communication with the Wiimote. wm_init has 4 parameters: device ID, initial data, calibration data, and an application function. The device ID depends on what type of controller you want to make, it's an array of 6 bytes. The initial data is the button press data that is sampled during game play, which should be set as a default state. The calibration data is an array of 32 bytes containing calibration data for the controller, this is composed of things like maximum/minimum joystick positions and things like that, I have no more details about this. The user application will link a function in the application, and it will be called every time the Wiimote requests a sample of button press data.

If you have the device detection pin of the extension port connected to an I/O on your microcontroller, then the wm_init function will simulate a disconnection and reconnection every time it is called. This is useful if you don't want your microcontroller to be powered by the extension port of the Wiimote.

Once wm_init has been called, button press data can be set by calling wm_newaction. The parameter is an array of 6 bytes containing the button press data. You can continuously call this function in your main application loop, when the Wiimotes samples the data, the latest data sent to wm_newaction will be read.

For various controller IDs, and information on the button press data array, visit .

Go to ... n/wii_drum and download:

Let me know what you think, I'd like comments about my coding, commenting, and the usability of the library.

Posts: 120
Joined: Fri Jun 15, 2007 1:04 am

Re: Wiimote Extension Library

by RLeyland on Thu Mar 19, 2009 3:40 pm

Thanks Frank,

This was a super addition, I've found it quite handy!

Posts: 6
Joined: Fri Jan 30, 2009 10:54 pm

Please be positive and constructive with your questions and comments.