Wii Nunchuck + Arduino = WTF!?!?!

I’ve just spent 2 hours browsing the web and trying out different code/library sets for the nunchuck, and I have to say, I am really aggravated. Can someone please point out one that works in the current IDE (perhaps that is the issue)… or, if anyone knows ANYTHING that can help me, please speak now…

I want to add a thanks in advance.


Sorry I’m not helping you, I’m just in the same WTF feeling u r experiencing …

I tried many tutorials and code samples found here and there, none seem to work out of the box.

Some say it is necessary to hack twi.h and uncomment #define ATMEGA8 and set a different FREQ, I tried, It doesn’t seem to be helping much …

I already have had partial results, meaning, scripts working but without the nunchuck … seems like the HandShake isn’t reached because I also see a freeze after the Serial.print (“Finished setup\n”); in many exemples
I dono if it is relevant but I had results with serial speeds of 9600, never with 19200

I’d also like to ear from successful nunchuck readings using Arduino IDE 0017, my nunchuck cables are red, white, yellow and Blue, I often read Green, I swapped the green for the blue to test the exemples, i also ignore the brown one …

any hints welcome

There’s an example at the bottom of the page.

I haven’t played with the nunchuck so I can’t say if it works or not… but I know a common mistake is if you’re using a mega, or a Seeeduino board, the Wii Nunchuck Adapter from Todbot won’t work without some modification… generally using a bread board or something.

Do let us know how you get along, and what your mistake was if you found it, I do plan on getting one of these bad boys soon! (they’re $6.99 with free shipping on eBay, how can you say no to that?)

Hope this helps! (I hope I didn’t shoot and miss and read over something important, :))

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

// 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;

I just tried AWOL’s code, still a no-go. I get the same issue - the handshake/setup completes, and I get one line of data after that:

Finished setup
100 100 100 100 100 0 0

Then everything stops. I should point out that I have a nunchuck from INTEC, not nintendo… but seeing as it is made for the Wii, I presume it utilizes the same exact communication protocol.

Have you got pull-ups on the I2C ?

Watchutalkingbout, fool?

This is my first encounter with I2C, so please explain :slight_smile:

Well, mine’s working without pull-ups, but you could try a 4K7 between SCL and 5V and the same value between SDA and 5V.

Still nothing. This is really starting to get annoying again.

Have you tried different addresses? I’m not sure how nintendo protocol works… but there may be multiple addresses that are capable. (maybe for multiple controllers?)

Try something like 0x50, 0x53, 0x51… anything that’s near… Maybe something a bit more extreme, but it’ll have to be within 0-127, so shouldn’t take too long to figure out if that’s the issue.

time for a “for” loop…

Well, I only get a response when the address is 0x52… so it’s not that… any other ideas?

It sounds like you were experiencing similar problems to the ones I’m getting now.

Just wondering if you ever found a solution?

nope, still nothing.

Sorry to hear that. Like REALLY sorry if you know what I mean?

I’ve kind of reached the end of the road with the nunchuck and arduino too. I’ve had so many problems; Arduino 0013 won’t load on my laptop but will on my desktop, whereas I can upload sketches on 0017 on my laptop but none at all on the desktop (just hangs when uploading) Firmata that came with 0017 was useless anyway (took me a while to figure that out) but even with the right Firmata it seems the only thing it’s good for is for reading the port and firmware version!

So anyway…rant over :-[

Not sure if this would help but I thought I’d add it to the discussion. I’ve been working on a Wii Nunchuck library that I could simply include in my programs without adding tons of code to the bottom of each file. You can check it out here:


It’s simply a reorganization of Todbot’s code as a C++ library. I haven’t finished it yet, but you’re welcome to use the code. It works with my Duemillanove and 0017 on my Mac with Snow Leopard.