The following may get you on the right track - works for me (proper Nintendo controller + Duemilanove)
//
// red 3.3V
// yellow clock (analogue pin 5)
// green data (analogue pin 4)
// white ground
//
#include <Wire.h>
#include <string.h>
#undef int
#include <stdio.h>
uint8_t outbuf[6];
int cnt = 0;
const byte ledPin = 13;
const int I2C_ADDR = 0x52;
int X_MIN = -100;
int X_MAX = 100;
int Y_MIN = -100;
int Y_MAX = 100;
int Z_MIN = -100;
int Z_MAX = 100;
int JX_MIN = -100;
int JX_MAX = 100;
int JY_MIN = -100;
int JY_MAX = 100;
void setup ()
{
Serial.begin (115200);
Serial.print ("Finished setup\n");
Wire.begin (); // join i2c bus with address 0x52
nunchuck_init (); // send the initilization handshake
}
void nunchuck_init ()
{
Wire.beginTransmission (I2C_ADDR); // transmit to device 0x52
Wire.send (0x40); // sends memory address
Wire.send (0x00); // sends sent a zero.
Wire.endTransmission (); // stop transmitting
}
void send_zero ()
{
Wire.beginTransmission (I2C_ADDR); // transmit to device 0x52
Wire.send (0x00); // sends one byte
Wire.endTransmission (); // stop transmitting
}
void loop ()
{
Wire.requestFrom (I2C_ADDR, 6); // request data from nunchuck
while (Wire.available ()){
outbuf[cnt] = nunchuk_decode_byte (Wire.receive ()); // receive byte as an integer
digitalWrite (ledPin, HIGH); // sets the LED on
cnt++;
}
// If we recieved the 6 bytes, then go print them
if (cnt >= 5)
{
print ();
}
cnt = 0;
send_zero (); // send the request for next bytes
delay (100);
}
void print ()
{
short joy_x_axis = outbuf[0];
short joy_y_axis = outbuf[1];
short accel_x_axis = (outbuf[2] << 2) + ((outbuf[5] >> 2) & 3);
short accel_y_axis = (outbuf[3] << 2) + ((outbuf[5] >> 4) & 3);
short accel_z_axis = (outbuf[4] << 2) + ((outbuf[5] >> 6) & 3);
byte z_button = !(outbuf[5] & 1);
byte c_button = !((outbuf[5] & 2)>>1);
accel_x_axis = map (accel_x_axis, 0, 1023, X_MIN, X_MAX);
accel_y_axis = map (accel_y_axis, 0, 1023, Y_MIN, Y_MAX);
accel_z_axis = map (accel_z_axis, 0, 1023, Z_MIN, Z_MAX);
joy_x_axis = map (joy_x_axis, 0, 255, JX_MIN, JX_MAX);
joy_y_axis = map (joy_y_axis, 0, 255, JY_MIN, JY_MAX);
Serial.print (joy_x_axis, DEC);
Serial.print ("\t");
Serial.print (joy_y_axis, DEC);
Serial.print ("\t");
Serial.print (accel_x_axis, DEC);
Serial.print ("\t");
Serial.print (accel_y_axis, DEC);
Serial.print ("\t");
Serial.print (accel_z_axis, DEC);
Serial.print ("\t");
Serial.print (z_button, DEC);
Serial.print ("\t");
Serial.print (c_button, DEC);
Serial.print ("\t");
Serial.print ("\r\n");
}
char nunchuk_decode_byte (char x)
{
return (x ^ 0x17) + 0x17;
}