Wii wireless nunchuck...

Hi, so i want to control my e-longboard with a nunchuck.

I found this code on the arduino site:

#include "Wire.h"
//#include "WiiChuckClass.h" //most likely its WiiChuck.h for the rest of us.
#include WiiChuck.h

WiiChuck chuck = WiiChuck();

void setup() {
//nunchuck_init();
Serial.begin(115200);
chuck.begin();
chuck.update();
//chuck.calibrateJoy();
}

void loop() {
delay(20);
chuck.update();

Serial.print(chuck.readJoyX());
Serial.print(", ");
Serial.print(chuck.readJoyY());
Serial.print(", ");

if (chuck.buttonZ) {
Serial.print("Z");
} else {
Serial.print("-");
}

Serial.print(", ");

//not a function// if (chuck.buttonC()) {
if (chuck.buttonC) {
Serial.print("C");
} else {
Serial.print("-");
}

Serial.println();

}

can anyone tell me how to connect the pins of the wireless dongle for the chuck into my uno? they don't seem to be defined in this code...? I'm confused #noob

It seems the pin assignments would be defined within the class. Check the .h files for more info.

Connect the dongle exactly the same way you would connect a wired nunchuck.

okay, so this webpage has the three files that I need apparently, but im quite nooby so how do i turn these into class files or libraries or whatever I need to make the code posted above work and find out the pin connections?

in fact is this what I need, if so how do i install it as a library?

in fact is this what I need,

No.

To wire up the nunchuck you need something like this break out board so you can get the connections into the Arduino.

You use the I2C bus to talk to it. Data is the A4 pin and Clock is the A5 pin on a Uno.

But this is a bit complicated because the Arduino has a 5V system and the nunchuck uses 3V3. The standard I2C library enables internal pull up resistors on the I2C lines so you have to use another library that is designed to have its pull up resistors disabled.
This is one such:-

You install it by doing this:-
http://www.arduino.cc/en/Guide/Libraries

Then you need to connect two external pull up resistors, one between A5 and the 3V3 and the other between A4 and the 3V3.

Once you have done this ( and connected the ground and the 3V3 power ) you are ready to program it.

You do not need to have a library specifically for the nunchuck, you can just give it the appropriate I2C commands. This is a small sample code to do this.

// Nunchuck test
// By Mike Cook
#include <I2C.h>
 
int outbuf[6];		// array to store results
void setup () {
  Serial.begin (19200);
  I2c.begin();
  I2c.pullup(0); // disable I2C pull ups
  I2c.timeOut(500); // half a second to prevent lock up
  Serial.print ("Finished setup\n");
  nunchuck_init (); // send the initialisation handshake
}

void nunchuck_init () {
 // I2c.write(address, registerAddress, data)  // set up start of read
  I2c.write(0x52, 0x40, 0x00);
}

void send_zero () { 
  I2c.write(0x52, 0x00);
}

void loop () {
 // I2c.read(address, numberBytes)
 Serial.println(" ");
 Serial.println("Raw data");
 I2c.read(0x52, 6);
 for(int j=0; j<6; j++){   // now get the bytes one at a time
      outbuf[j] =  I2c.receive();     // receive a byte
      if(outbuf[j] < 0x10) Serial.print("0"); // print leading zero if needed
      Serial.print(outbuf[j], HEX);          // print the byte
      Serial.print(" ");         
     }
     Serial.println(" ");  // new line
   printResults();  
  send_zero (); // send the request for next bytes
  delay (800);
}

// Print the input data we have received
// accel data is 10 bits long
// so we read 8 bits and the LS bits are in the last byte
void printResults ()
{
  int z_button = 0;
  int c_button = 0;

 // byte outbuf[5] contains bits for z and c buttons
 // it also contains the least significant bits for the accelerometer data
 // so we have to check each bit of byte outbuf[5]
 z_button = outbuf[5] & 1;
 c_button = 1 ^ ((outbuf[5] >> 1) & 1) ^ (outbuf[5] & 1);
 
 outbuf[2] = (outbuf[2] << 2) | (outbuf[5] >> 2) & 0x3; // acc x
 outbuf[3] = (outbuf[3] << 2) | (outbuf[5] >> 4) & 0x3; // acc y
 outbuf[4] = (outbuf[4] << 2) | (outbuf[5] >> 6) & 0x3; // acc x
 for(int i=0; i<5; i++){
  Serial.print (outbuf[i], DEC);
  Serial.print ("\t");
 }
  Serial.print (z_button, DEC);
  Serial.print ("\t");

  Serial.print (c_button, DEC);
  Serial.print ("\t");

  Serial.println(" ");
}

In your sketch folder, create a folder called 'libraries' if it does not exist.
Inside the 'libraries' folder create a folder called 'WiiChuck'.
Inside the 'WiiChuck' folder put the file WiiChuck.h: http://playground.arduino.cc/Main/WiiChuckClass?action=sourceblock&num=2
Inside the 'WiiChuck' folder create a folder called 'examples'.
Inside the 'examples' folder create a folder called 'demo'.
Inside the 'demo' folder place the file demo.ino: Arduino Playground - WiiChuckClass

Re-start the IDE. Load the sketch File->Examples->WiiChuck->demo and try to verify it (leftmost button in the header of the sketch).

Hi, thanks for your replies. I have managed to get it to compile now. My adaptor board is on its way too!

I am also going to try this code: wiichuck_adapter/nunchuck_funcs.h at master · todbot/wiichuck_adapter · GitHub

does it look any good to you guys?