How To Control Your Robot Using A Wii Nunchuck An
How To Control Your Robot Using A Wii Nunchuck An
Table of Contents
Step 2: Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 3: Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 4: Finished . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
Intro: Control Your Robot Using a Wii Nunchuck (and an Arduino)
After wearing myself out playing Wii Boxing I got to thinking wouldn't it be great if I could use this to control my robot, (looking to my left hand).
Looking around the internet I found a bevy of people doing similar things, (links to everyone just below the video). So what follows is a re-packaging of all their hard work,
resulting in a robot controllable by both the Wii nunchuck's joystick or more interestingly its accelerometers.
A quick video of my Arduino Controlled Servo Robot - (SERB) being controlled by a Wii nunchuck.
(resources)
(here) - Arduino Code - Chad at WindMeadows.com has written excellent arduino code for reading the Wii nunchuck. Code which I have included pretty much
verbatim in this project. if you're interested in more technical details this is where to look.
(here) - Nunchuck Details - WiiLi.org has a great wiki about all things Wii, this is a link to a page that describes the nunchucks protocol and how to calibrate your
nunchuck.
(here) - WiiChuck Adapter - Tod of todbot.com very kindly produced a small adapter to make plugging your nunchuck into a breadboard particularly easy.
(similar projects)
(here) - Wireless Nunchuck Control - Frank over at Society of Robots went one step further adding a wireless link so he can control his Arduino robot with all
the tilt and twist fun from afar.
(here) - Nunchuck Controlled Pan and Tilt Camera - Using a Nunchuck and an Arduino to control the pan and tilt of a camera.
(here) - Nunchuck and Arduino Controlled Canoe - Finally a rather epic project that uses an Arduino, nunchuck, servos and small trolling motor to drive a
Canoe.
(if you have an Arduino nunchuck project you've completed drop me a line and it can be added here)
(shameless plug)
To check out more of our lovely open source projects - oomlout.com
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
Step 1: Parts & Tools
Only a few parts to collect before we get wiring and programming
We use an Arduino Controlled Servo Robot - (SERB) however any Arduino powered dual servo robot will work. Other options (here)
Electronics - ($24)
Image Notes
1. Wii Nunchuck - (x1) - Available online or from your nearest Blockbuster
2. Wiichuck Adapter - (x1) - Available from FunGizmos.com
3. A few Pieces of Breadboard wire (22 awg solid)
4. Arduino Controlled Servo Robot - (SERB) - build your own or kits available from oomlout.com
Step 2: Wiring
Wiring this up could not be simpler, and requires only four wires.
Explained
Pictorially
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
Image Notes
1. The breadboard as viewed from above
File Downloads
(many thanks to chad at windmeadow.com for doing the research and writing really easily understood Arduino code to interact with the Wii nunchuck, the program below
includes his code virtually unchanged).
What it does
The program will default to using the nunchucks joystick for control. If you push the stick forward your robot will go forward, reverse, backwards and so on.
If you hold down the "Z" button (the big one on the front). Your robot will now move based on the tilt of the nunchuck. Tilt forward to go forward...
Finally if it isn't quite working the program will send the state of the nunchucks buttons, joystick and accelerometers, every second over the Arduino's USB port.
(just open the debug window at 9600 to see this data)
Appendix 1 - _SERB_WiiNunchuckControl.pde
//START OF NUNCHUCK PREAMBLE - For more in depth information please visit the original source of this code http://www.windmeadow.com/node/42
//-------------------------------------------------
/*
* Wiring Details
* white - ground
* red - 3.3+v - 5 volts seems to work
* green - data - Analog 4
* yellow - clock - Analog 5
*/
#include #include #undef int #include uint8_t outbuf[6]; // array to store arduino output int cnt = 0; // counter used for nunchuck
nunchuckValues[CBUTTON] = 0;
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
void send_zero () {
Wire.beginTransmission (0x52); // transmit to device 0x52
Wire.send (0x00); // sends one byte
Wire.endTransmission (); // stop transmitting
}
//END OF NUNCHUCK CODE - For more in depth information please visit the
//original source of this code http://www.windmeadow.com/node/42
//---------------------------------------------------------------
//------------------------------------------------------------------------
//START OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES
/*
* sets up your arduino to address your SERB using the included routines
*/
void serbSetup(){
setSpeed(speed);
pinMode(LEFTSERVOPIN, OUTPUT); //sets the left servo signal pin
//to output
pinMode(RIGHTSERVOPIN, OUTPUT); //sets the right servo signal pin
//to output
leftServo.attach(LEFTSERVOPIN); //attaches left servo
rightServo.attach(RIGHTSERVOPIN); //attaches right servo
goStop();
}
/*
* sets the speed of the robot between 0-(stopped) and 100-(full speed)
* NOTE: speed will not change the current speed you must change speed
* then call one of the go methods before changes occur.
*/
void setSpeed(int newSpeed){
if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100
//make it 100
if(newSpeed <= 0) {newSpeed = 0;} //if speed is less than 0 make
//it 0
speed = newSpeed * MAXSPEED / 100; //scales the speed to be
//between 0 and MAXSPEED
}
/*
* sets the speed of the robots rightServo between -100-(reversed) and 100-(forward)
* NOTE: calls to this routine will take effect imediatly
*/
void setSpeedRight(int newSpeed){
if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100
//make it 100
if(newSpeed <= -100) {newSpeed = -100;} //if speed is less than -100 make
//it -100
rightSpeed = newSpeed * MAXSPEED / 100; //scales the speed to be
//between -MAXSPEED and MAXSPEED
rightServo.write(90 - rightSpeed); //sends the new value to the servo
}
/*
* sets the speed of the robots leftServo between -100-(reversed) and 100-(forward)
* NOTE: calls to this routine will take effect imediatly
*/
void setSpeedLeft(int newSpeed){
if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100
//make it 100
if(newSpeed <= -100) {newSpeed = -100;} //if speed is less than -100 make
//it -100
leftSpeed = newSpeed * MAXSPEED / 100; //scales the speed to be
//between -MAXSPEED and MAXSPEED
leftServo.write(90 + leftSpeed); //sends the new value to the servo
}
/*
* sends the robot forwards
*/
void goForward(){
leftServo.write(90 + speed);
rightServo.write(90 - speed);
}
/*
* sends the robot backwards
*/
void goBackward(){
leftServo.write(90 - speed);
rightServo.write(90 + speed);
}
/*
* sends the robot right
*/
void goRight(){
leftServo.write(90 + speed);
rightServo.write(90 + speed);
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
}
/*
* sends the robot left
*/
void goLeft(){
leftServo.write(90 - speed);
rightServo.write(90 - speed);
}
/*
* stops the robot
*/
void goStop(){
leftServo.write(90);
rightServo.write(90);
}
//END OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES
//---------------------------------------------------------------------------
//Prints the Nunchucks last read data (must call NUN_readNunchuck(); before calling
void printData(){
Serial.print("XJoy= ");Serial.print (getNunValue(XSTICK), DEC); Serial.print ("\t");
Serial.print("YJoy= ");Serial.print (getNunValue(YSTICK), DEC); Serial.print ("\t");
Serial.print("XGs= ");Serial.print (getXGs() * 1000, DEC); Serial.print ("\t");
Serial.print("YGs= ");Serial.print (getYGs() * 1000, DEC); Serial.print ("\t");
Serial.print("ZGs= ");Serial.print (getZGs() * 1000, DEC); Serial.print ("\t");
Serial.print("ZBut= ");Serial.print (getNunValue(ZBUTTON), DEC); Serial.print ("\t");
Serial.print("YBut= ");Serial.print (getNunValue(CBUTTON), DEC); Serial.print ("\t");
}
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
Step 4: Finished
I hope you've gotten it working and are having fun tilting and driving.
If its not quite working leave a message or send us an e-mail at [email protected] and we'll try our best to help you get it working.
(shameless plug)
For more fun open source projects try visiting us at oomlout.com
Related Instructables
Comments
37 comments Add Comment
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
Asuraku says: Nov 28, 2009. 6:27 PM REPLY
This code is an absolute mess and I can't seem to figure out how to fix it. Could someone post an un-scrambled working copy?
http://www.flickr.com/photos/14462918@N03/3970656962/
The video pretty much shows the problem...NOTHING WORKS! By the way I just spent around $100 on this project and I was hoping that it would work.
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
fred_thedog says: Jun 8, 2009. 4:24 PM REPLY
I get the same error as TXTCLA55. Haven't spent any time trying to find the problem yet though.
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/
wolf555hound says: Dec 19, 2008. 5:26 PM REPLY
OMG, you stole MY method!!! hehe
http://www.instructables.com/id/How-to-Control-Your-Robot-Using-a-Wii-Nunchuck-an/