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
Attachments
Step 4: Done!!!
You can now control the 2 servos throught the wii nunchuck.Hope you enjoy!!
16 Comments
Question 2 years ago
Where do those two random white and green wires go?
Question 5 years ago
can I do it with one servo?
Answer 5 years ago
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!
7 years ago
ciao ho provato il codice... avrei una domanda come faccio funzionare i due servo con il joy senza muovere il telecomando ?
Reply 7 years ago
Non riesco a capire quello che voglio dire.Prova a scrivere in inglese.
7 years ago
I can't download the code, can u just write it on step #3
Reply 7 years ago
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);
}
}
7 years ago
I made it ! Very cool & fun !
But... Same question as @Alienpuppy : can you explain the setup ?
Thanks !
7 years ago
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!
7 years ago
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!
7 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!
Reply 7 years ago
Given him then also a free version of your software ;-)
Reply 7 years ago
You can always run Visuino for 5 minutes at a time, which is actually more than enough time to make this project ;-)
Reply 7 years ago
And if he contact me, I will give him a free version :-)
7 years ago
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.
7 years ago
Fun way to control an Arduino project.