# Specific 3D Printing Applications / Fields / Conferences > 3D Printing in Robotics >  Hacking a Wii Nun-Chuck Controller (wired and wireless) to control your Robot - Pt 1

## Geoff

Why would I want to use a Nunchuck to control my robot?

Why not  :Smile:  

Besides the low cost (a wireless nunchuck I  purchased only cost me $5 brand new, and it came with 2xAAA  rechargable energizer batteries, worth $4 in themselves!.


Besides cost, its the innards that got my attention. For that small  price, you get an Analogue control stick, 2 buttons and the best part, a  three-axis accelerometer for motion-sensing and tilting. And if you buy  a wireless one, you also get a 2.4gig receiver with it. Alongside all  that, Communications are bidirectional synchronous serial I2C meaning  you can communicate with it and also send commands to it while receiving  them.


So... if you buy the cheapest, or one of the cheapest arduino sticks,  these can be easily hooked up into them. So for under $20 you could have  the entire solution bundled up and built within about an hour or two,  less even. 


The pictures below show my current progress. Before attempting to tackle  anything regarding actually using the nunchuck as a control device, I  need to find out all the serial information that it is sending so I can  then use that in my quest. How each control will be implemented I have  not decided as yet, but it is definitely on the right track. 


*Picture 1.*
 Shows the mess of experimentation and the lack of an  expansion board.
 The idea here was basically to retrieve the information  from the chuck without the need for a serial monitor, but simply an LCD  screen. The numbers are indicated in the first picture.


Please take note, the analogue X,Y is not calibrated! it should be  128/128- and this is a $50 official Nintendo Wii chuck. Keep that in  mind when you see the $4 wireless calibration.





The figures are denoted in the picture. I have the Wii lying sideways so  of course the accelerometer is showing odd readings. So mission  success! I will document the process as best I can if anyone else wants  to have a go.


Parts you will require:



Wii nunchuckArduino processor, just about any type I am using an cheap  clone, which is a freetronics eleven board, which has some nice features  and was about $25. NOTE ARDUINO MEGA USERS - you have dedicated I2C  ports, so you cant use analogue ports 4 and 5. Use.. 20/21 i think.4 x small wires if you are soldering, 4 breadboard jumpers  if you are not or dont want to damage your nunchuck. This can all be  done externally and does not require opening the nunchuck (unless you  like getting your hands dirty :I )Latest version of Arduino, which can be found here: http://arduino.cc/en/Main/Software 

The nunchuck C library (github) https://github.com/todbot/wiichuck_adapter 




OPTIONAL


This is a handy thing I saw, I dont have one but it can save you the wires (not that 4 wires is a big deal really..)




These are available for sale at http://store.fungizmos.com/items/212 for about $4


*Onward with the construction...*


If you look down the barrel of your nunchuck remote, you will see 6 pins. *They are as follows.* 




There is really 4 wires you need to worry about. And do not pay attention to colours!! 


Wii adapters will use different colour wires, so you want to use the plug as your guide. 


1. GND goes to GND on your Arduino, any ground.
2. 3.3v goes to the 5v+Vin on your arduino
3. SDA goes to Analogue pin 4
4. SCL goes to Analogue pin 5











Quite simply connected, the breadboard jumpers will actually fit in the  pin holes above the slots and you need not even solder for this testing.  If its an old wii chuck, go for it, rip the end off and hard wire the  sucker! 


It's pretty straight forward 


I learnt everything from this website, please go here for any additional help with the libraries: 

http://todbot.com/blog/2008/02/18/wi...ter-available/

That's where I got started.




So, we have it hooked up, now what do we do? The code to access the  chuck is very simply, all we need to do is initialise it. Of course make  sure your port is selected in Arduino and your board is plugged in.


So for a simple starter program, try this. Go into Arduino, if you  installed the library and it wont show, restart the program. Once you  find it, go to Examples and load the nunchuck demo.


code should look as below:




> /* * ArduinoNunchukDemo.ino
> *
> * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
> *
> * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
> *
> */
> 
> 
> ...


Now, this is pretty easy to understand. As you can see all we are doing  is accessing Gabs wonderful library and assigning the chucks output to  the serial port. Now, I wanted to do this with the LCD shield (16x2) so I  modified it simply to the following:




> #include <ArduinoNunchuk.h>
> 
> 
> #include <Wire.h>
> #include <LiquidCrystal.h>
> 
> 
> ArduinoNunchuk nunchuk = ArduinoNunchuk();
> LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
> ...


So basically the same thing, but instead of having to view the serial  monitor I can check the screen to make sure it's working OK.

Now that we have our code to figure out the values for the nunchucks output, I worked at cleaning it up a bit.

I got my $4 brand new wireless nunchuck, ripped apart the receiver and hooked that up instead. 

Now, I did need a Wii controller to plug the receiver into just to get  the nunchuck to sync to the receiver - but the Wii controller had no  batteries or was not actually connected to the wii, so it is obviously  just a combinations of pins being accessed to trick the receiver into  thinking there is a working wii controller plugged into it, but this is a  very small issue, even if I can't figure out the combination I can wire  a dummy loopback on the receiver and wire it in permanently, I will  see.

Once again, take note of the X/Y calibration - perfect. Out of the box,  not a degree off, as opposed to the official one that always will be  slightly off. I don't know why, and I don't know how to calibrate them,  all you can do is compensate for the miscalibration, in the case of the  wired chuck in the first picture I would just start my RCS translation  at a 0,0 of 121/128 and calculate from then on, with the wireless chuck  no need for anything the things well balance and the accelerometer works  very very well.



So as you can see, alot neater  the shield allows me to share I/O pins on the arduino and remove the need for an ugly breadboard. 

  Technically we don't need a driver as we are dealing with direct serial  communication, so really all I am looking for is the figures the  nunchuck throws back and then utilising them in some clever way to control my robots remotely.

*Anyway.. That concludes Part 1.. in Part 2 I will be hooking this up to my Hexapod and we will start programming the pod to take commands from the chuck,
*

----------

