Arduino Wii Nunchuck Controller

14,414

305

15

Published

Introduction: Arduino Wii Nunchuck Controller

How to control 2 servos thought the wii nunchuck.

Step 1: Parts

Wii nunchuck

Arduino

2 Servo

Breadboard

Jumper Wires

Step 2: Connect

Connect the wii nunchuck like this schematic.

Step 3: Upload the Code


Step 4: Done!!!

You can now control the 2 servos throught the wii nunchuck.Hope you enjoy!!

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Clocks Contest

      Clocks Contest
    • Water Contest

      Water Contest

    15 Discussions

    Of course, you can. Just don't add one servo. Or, if you want to change the code, you can tell me here or on a pm and I will help you!

    ciao ho provato il codice... avrei una domanda come faccio funzionare i due servo con il joy senza muovere il telecomando ?

    1 reply

    Non riesco a capire quello che voglio dire.Prova a scrivere in inglese.

    I can't download the code, can u just write it on step #3

    1 reply

    Here you are!!


    #include <Servo.h>
    Servo servo1;
    Servo servo2;
    #include <Wire.h>


    #define ZEROX 530
    #define ZEROY 530
    #define ZEROZ 530


    #define WII_NUNCHUK_I2C_ADDRESS 0x52



    int counter;


    uint8_t data[6];

    void setup()
    {

    servo1.attach(11);
    servo2.attach(12);


    Wire.begin();

    Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
    Wire.write(0xF0);
    Wire.write(0x55);
    Wire.endTransmission();

    Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
    Wire.write(0xFB);
    Wire.write(0x00);
    Wire.endTransmission();
    }

    void loop()
    {

    Wire.requestFrom(WII_NUNCHUK_I2C_ADDRESS, 6);

    counter = 0;

    while(Wire.available())
    {

    data[counter++] = Wire.read();
    }


    Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
    Wire.write(0x00);
    Wire.endTransmission();

    if(counter >= 5)
    {

    double accelX = ((data[2] << 2) + ((data[5] >> 2) & 0x03) - ZEROX);
    double accelY = ((data[3] << 2) + ((data[5] >> 4) & 0x03) - ZEROY);
    double accelZ = ((data[4] << 2) + ((data[5] >> 6) & 0x03) - ZEROZ);

    int value = constrain(accelY, -180, 180);

    value = map(value, -180, 180, 0, 180);

    servo1.write(value);


    value = constrain(accelX, -180, 180);
    value = map(value, -180, 180, 0, 180);
    servo2.write(value);


    delay(20);
    }
    }

    I made it ! Very cool & fun !

    But... Same question as @Alienpuppy : can you explain the setup ?

    Thanks !

    Just made it! thanks only issiue that i had when i groundeed out the wii remote on the breadboard, the servos would pickup some sort of interferance. i just groiunded out on the board seems to work fine!

    This is great! I want to try it out.

    One question... I don't understand the setup() part of the code. Can you explain the values you write to the nunchuk when it is initialized... I'm assuming it is some initialization protocol, but it differs from another one I found on the web.
    Do you have a nunchuk protocol document you could share?

    This is the one I found:
    http://www.robotshop.com/media/files/PDF/inex-zx-n...

    It says to write 0x40 and 0x00 to initialize.
    Your code writes 0xF0 and 0x55... followed by 0xFB and 0x00.

    Thanks!

    0
    user
    BoianM

    2 years ago

    Cool! After seeing this, I added support for Wii Nunchuck in Visuino, and included similar Demo project :-)
    Thank you for the great idea!

    3 replies

    Given him then also a free version of your software ;-)

    You can always run Visuino for 5 minutes at a time, which is actually more than enough time to make this project ;-)

    And if he contact me, I will give him a free version :-)

    Nice work - I've done a similar project. The servos will be less jittery if you give them a separate power supply from the Arduino.