post by ntgr on Jan 29, 2010

Hi.
I bought cheap nunchuck from China and it would not work whatever i do. :-[
Firstly i tested it with an original wii system and the nunchuck was working fine.
But when i try to connect it in my arduino...i get nothing.
Any one got an idea why ??
Thnx in advance.

read 5 min

post by system on Jan 30, 2010

Do you have it wired right? What code are you using?

We need more information here before we can speculate on the problem.

post by ntgr on Jan 30, 2010

Thnx digimike for your reply.

Do you have it wired right? What code are you using?

Yes i m sure that is wired right. I also open it and take some readings with the multimeter in the accelerometer exit.
The code im using is Index of /arduino/sketches/NunchuckPrint. I v also tested almost every code i v found in the internet .

post by ntgr on Jan 30, 2010

post by crimony on Jan 30, 2010

Wii "Extension Controllers" other than the original Nunchuck have an initialisation sequence which differs from the one found in the nunchuck library originally designed by Tim Hirzel. I found this out when I tried to use a Wii "Classic Controller".

To initialise anything other than an OEM Nunchuck, you need to replace this in the init call:

    Wire.begin();                // join i2c bus as master
    Wire.beginTransmission(0x52);// transmit to device 0x52
    Wire.send(0x40);// sends memory address
    Wire.send(0x00);// sends sent a zero.  
    Wire.endTransmission();// stop transmitting

With this:

byte cnt;

Wire.begin();
            
// init controller 
delay(1);
Wire.beginTransmission(0x52);      // device address
Wire.send(0xF0);                    // 1st initialisation register
Wire.send(0x55);                    // 1st initialisation value
Wire.endTransmission();
delay(1);
Wire.beginTransmission(0x52);
Wire.send(0xFB);                    // 2nd initialisation register
Wire.send(0x00);                    // 2nd initialisation value
Wire.endTransmission();
delay(1);
            
// read the extension type from the register block        
Wire.beginTransmission(0x52);
Wire.send(0xFA);                    // extension type register
Wire.endTransmission();
Wire.beginTransmission(0x52);
Wire.requestFrom(0x52, 6);               // request data from controller
for (cnt = 0; cnt < 6; cnt++) {
    if (Wire.available()) {
        ctrlr_type[cnt] = Wire.receive(); // Should be 0x0000 A420 0101 for Classic Controller, 0x0000 A420 0000 for nunchuck
    }
}
Wire.endTransmission();
delay(1);
            
// send the crypto key (zeros), in 3 blocks of 6, 6 & 4.
Wire.beginTransmission(0x52);
Wire.send(0xF0);                    // crypto key command register
Wire.send(0xAA);                    // sends crypto enable notice
Wire.endTransmission();
delay(1);
Wire.beginTransmission(0x52);
Wire.send(0x40);                    // crypto key data address
for (cnt = 0; cnt < 6; cnt++) {
    Wire.send(0x00);                    // sends 1st key block (zeros)
}
Wire.endTransmission();
Wire.beginTransmission(0x52);
Wire.send(0x40);                    // sends memory address
for (cnt = 6; cnt < 12; cnt++) {
    Wire.send(0x00);                    // sends 2nd key block (zeros)
}
Wire.endTransmission();
Wire.beginTransmission(0x52);
Wire.send(0x40);                    // sends memory address
for (cnt = 12; cnt < 16; cnt++) {
    Wire.send(0x00);                    // sends 3rd key block (zeros)
}
Wire.endTransmission();
delay(1);
// end device init

Also somewhere you'll need to store the ctrlr_type that you collected in the routine, its type is (make it global or whatever you like):

uint8_t ctrlr_type[6];

This works for my Classic Controller and my nunchuck, even though the old code also worked for my nunchuck.

The inspiration for this code came from the wiibrew site, Wiimote - WiiBrew

post by ntgr on Jan 31, 2010

17 days later

post by turbosharp on Feb 17, 2010

post by system on Feb 17, 2010

post by turbosharp on Feb 17, 2010

3 months later

post by system on May 14, 2010

10 days later

post by system on May 24, 2010

post by system on May 25, 2010

post by system on May 31, 2010

5 months later

post by system on Nov 7, 2010

post by system on Nov 8, 2010

1 month later

post by lestofante on Dec 19, 2010

1 month later

post by arbarnhart on Jan 21, 2011

10 years later

Closed on May 6, 2021