With-wii-nunchuck

This example shows how to connect a Pinguino board to the Wii Nunchuck.

For this test, we used an original Nunchuck from Nintendo. With compatible model, you need to adapt some value ( delay ).

The nunchuck can be used as a 3 axis accelerometer, an analog stick and 2 buttons.

The code uses the LibI2C module in Pinguino. We adapted the I2C initialisation to work with a clock frequency of 100 kHz. The output sends value to the serial port.

The beta 9-05 version is used to compile the code.

How to connect it ?
A piece of double-sided PCB has been used to make a male connector.



Pinguino is connected to the Nunchuck via the I2C bus.

SCL is PIN 0 and SDA is PIN 1.

The nunchuck is powered from the 5vcc Pinguino power supply.

Pinguino Breadboard


Two 22k resistors are used as pull-ups on the SDA and SCL lines.

Test is on a 18F2550 Pinguino but it can also be wired on a 18F4550.

The code
6 bytes are read from the nunchuck. Each byte is the value of a sensor.

byte 0 is the X analog value of the analog stick, byte 1 is the Y analog value of the analog stick,

byte 2 is the X value of the 10 bit accelerometer (bits 2-9), byte 3 is the Y value of the 10 bit accelerometer (bits 2-9), byte 4 is the Z value of the 10 bit accelerometer (bits 2-9),


 * byte 5
 * bit 7-6 is bit 1-0 of the X accelerometer data,
 * bit 5-4 is bit 1-0 of the Y accelerometer data,
 * bit 3-2 is bit 1-0 of the Z accelerometer data,
 * bit 1 is the state of the C button ( 0=pressed ),
 * bit 0 is the state of the Z button ( 0=pressed ).

More about the nunchuck
WiiBrew website