Hi all,this post is an "how to" for an Arduino pan and tilt camera moved by a Nintendo Wii Nunchuck.Here's the video so you can check how it'll be the result. The most important thing is the precision and responsiveness of the system.Here it is for all that asked me in the past and for those interested in putting something similar in their UAVs.It's an "old" project I've posted the following video on YouTube more than a 5 months ago but never had the time to post schematics and the code online, even if a lot of people asked for it.I use an Arduino Diecimila board to have a Nintendo Wii Nunchuck control a camera mounted on a pan and tilt mechanism with two servos (Hitech HS-422).Nunchuck's accelerometer (an ADXL330) is used to move the camera.As you can see, if the Nunchuck's "Z" button is pressed, the camera position is locked.Here is picture of the pan&tilt mechanics with servos:First of all I got to thank a few people that before me putted their experiences online. That simple project is based on the code and infos found on the following pages:Read wii nunchuck data into arduinohttp://www.windmeadow.com/node/42Boarduino, Wii Nunchucks, and Servoshttp://todbot.com/blog/2007/10/25/boarduino-wii-nunchuck-servo/Here's a simple schematics on how to connect the servos and Nunchuck to the Arduino. Servo's pins are 6 and 7.The code is here.You can find more infos about the code in the two links I mentioned before, but feel free to ask.The only section you should customize to adapt to your servos an need is a list of variables:refreshTime (set to 20) - minimum refresh time for servo pulseminPulse (set to 1000) - minimum pulse value for servo 1minPulse2 (set to 500) - minimum pulse value for servo 2dtime (set to10) - delay (in milliseconds) for each looppwbuffsize (set to 10) - how many values has to be buffered and the averaged (that's the same value for both servos)Next post will be regarding the evolution of that interface: changed camera and servos with a smaller and ligher one (this one) and made the connection between the Nunchuck and the camera, wireless.Hope that can be helpful and feel free to ask anything about that.Thank you and ciao,Andrea
This is a perfect starting point for a project I'm working on but I'm is shanghai and your ideavirus server is blocked in China so I can't see the code. Would you mind posting it on diydrones ? many thanks.
Hey Andrea, your Nunchuck hack works like a dream!!! I had to search some wiki to find out how the connector wiring was pinned because my chinese Nunchuck has not the same wire colors as yours. In case some other people get an Ebay Nunchuck from China, that's how it is wired:
VCC = Brown (I connected at +3.3V)
GND = White
Data = Green
Clock = Blue
I have one more Black wire to the connector shield.
Well, this was to tell that it works very nicely after setting up minPulse variables to get the Nunchuck centered as I wanted it.
I would like to avoid the very tiny servos movements when the Nunchuck is staying almost without moving. Would you have some suggestion for code modification to try maybe to average 3 consecutive pulsewidths, or eventually to discard servo movement if absolute value of new pulsewidth minus old pulsewidth is lower than some threshold?
I am very new at Arduino and coding is not easy for me. If you or anybody have some suggestion about the best way to make the servos stay still when there is almost no movement on the Nunchuck, that would very useful and I would be very grateful.
A I said before, I am eager to play with my Nunchuck and Arduino. I'll use the +3.3V connector of the Arduino to power the device. Since, as I read, the Nunchuck uses the "fast" i2C protocol, the TWI frequency of wire.h arduino library has to be changed to 400kHz for a +5V powered Nunchuck. If the device is powered with the +3.3V supply, the frequency should be set to 100kHz. So I'll change the wire.h TWI_FREQ line to "#define TWI_FREQ 100000L". I think the +3.3V is better suited for the Nunchuck. I read somewhere (forgot to bookmark) the Vcc should be below 4V!
I'll report back once if it works. In the meantime, if this setting seems strange to someone, please let me know. I also hope the current draw of the Nunchuck is not more than the arduino +3.3V port can deliver.
I just got my brand new chinese Nunchuck today and I am eager to try this out. Before I start, I have a basic question: why connect the Nunchuck to 5V since it is a 3.3V device? Isn't the higher Vcc going to shorten the life span of the Nunchuck? Could I use the 3.3V port of my Duemilanove Arduino board instead for powering the Nunchuck or is there code to modify for this to run? Thanks for helping a newbie!
Can't we modify the code? Instead of using pinout 6 & 7 output 2 single servo pulse for controlling 2 servos,we use pinout 6 or 7 ONLY to send out a series of 8 channel pulse train(channel 7 & 8 for camera pan & tilt controls).then we can hook it up to Futaba remote with trainer connection .We can build our own head tracking camera control for FPV piloting.
Can someone answer the above post please? I am having the same problem with vista.
I get the error message:
Couldn't determine program size: C:\Users\albert\Desktop\arduino-0011\hardware/tools/avr/bin/avr-size: 'C:\Users\alber\AppData\Local\Temp\build3482.tmp\wiinunchuck.hex': No such file
hi I am trying to duplicate what you are doing it is very cool. I am new to this and I can't figure out how to get the code to upload to the arduino. It keeps giving me messages like this
"/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected unqualified-id before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected unqualified-id before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__put' was not declared in this scope
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'char'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__get' was not declared in this scope
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: initializer expression list treated as compound expression
Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex': No such file
avrdude: can't open input file /Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex: No such file or directory
avrdude: write to file '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex' failed"
Help would be greatly appreciated. If there is an error in your code or if you know how to fix it just let me know.
Comments
This is a perfect starting point for a project I'm working on but I'm is shanghai and your ideavirus server is blocked in China so I can't see the code. Would you mind posting it on diydrones ? many thanks.
VCC = Brown (I connected at +3.3V)
GND = White
Data = Green
Clock = Blue
I have one more Black wire to the connector shield.
Well, this was to tell that it works very nicely after setting up minPulse variables to get the Nunchuck centered as I wanted it.
I would like to avoid the very tiny servos movements when the Nunchuck is staying almost without moving. Would you have some suggestion for code modification to try maybe to average 3 consecutive pulsewidths, or eventually to discard servo movement if absolute value of new pulsewidth minus old pulsewidth is lower than some threshold?
I am very new at Arduino and coding is not easy for me. If you or anybody have some suggestion about the best way to make the servos stay still when there is almost no movement on the Nunchuck, that would very useful and I would be very grateful.
you are right. You can use the 3.3V that the Arduino board has. It's between the RESET and the regulat 5V output. I hope this helps.
Andrea
I'll report back once if it works. In the meantime, if this setting seems strange to someone, please let me know. I also hope the current draw of the Nunchuck is not more than the arduino +3.3V port can deliver.
I get the error message:
Couldn't determine program size: C:\Users\albert\Desktop\arduino-0011\hardware/tools/avr/bin/avr-size: 'C:\Users\alber\AppData\Local\Temp\build3482.tmp\wiinunchuck.hex': No such file
Thanks
"/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected unqualified-id before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected unqualified-id before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__put' was not declared in this scope
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'char'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__get' was not declared in this scope
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'
/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: initializer expression list treated as compound expression
Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex': No such file
avrdude: can't open input file /Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex: No such file or directory
avrdude: write to file '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex' failed"
Help would be greatly appreciated. If there is an error in your code or if you know how to fix it just let me know.
Thanks