How to: Arduino and Nintendo Nunchuck for pan and tilt camera interface

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 arduino
http://www.windmeadow.com/node/42

Boarduino, Wii Nunchucks, and Servos
http://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 pulse
minPulse (set to 1000) - minimum pulse value for servo 1
minPulse2 (set to 500) - minimum pulse value for servo 2
dtime (set to10) - delay (in milliseconds) for each loop
pwbuffsize (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

Views: 32320

Tags: accelerometer, adxl330, arduino, camera, nunchuck, pan, servo, tilt


3D Robotics
Comment by Chris Anderson on April 12, 2008 at 3:29pm
So cool! Now just interface it with a RC transmitter, and you've got a great FPV setup...
Comment by dincer hepguler on April 14, 2008 at 7:45am
Hi Andrea,
i tried many Arduino sketches for nunchuck and servos but yours is the best one. very responsive... i am now trying to use your setup other way round. i will not use this for Gimbal camera but instead i will use the nunchuck servo response for actually stabilizing the plane. only rudder and elevator control. i have to find a way to stabilize the altitude... trying... as of your Thermal Sensing idea, can we use the Z-axis of the accelerometer For g sensing upwards? furthermore can we combine this with an on-board thermometer?... must think over... just brainstorming... :)

dincer
Comment by Andrea Salvatore on April 14, 2008 at 11:19am
Ciao Dincer,

thanks!

That's exactly what I'll do: use a Nunckuck as a controller for my RC airplane. Maybe the next post will have a simple schematic of it. It's very easy to implement and it can be used as a 3channel radio command. But more intuitive, in my opinion.

I made some test and the Nunchuck z-axis is not usable. I'll use an accelerometer and a gyro (on an IMU board) on the airplane for the autopilot (maybe I'll put a compass too). The Nunchuck is more than enough for piloting.

I'm thinking about having an LCD display attached to the microcoputer (that's in the case I'll use a Gumstix). That could give me the possibility to have telemetry, GPS control/programming, Nunchkuck control all in one box. That'd be cool.

Why do you want to add a thermometer onboard? For thermals? As I told you probably I'll test an infrared thermal array to "see" thermals. Hoping it's good enough for it. I doubt but it's a test that has to be done.

Lot's of brainstorming :D

Ciao,

Andrea
Comment by dincer hepguler on April 15, 2008 at 10:10am
hi Andrea,
indeed i checked the Nunchuck data with Tod Kurt's NunchuckPrint sketch which can be found at http://todbot.com/arduino/sketches/NunchuckPrint/ and see that z-axis response is weak, only fast vertical movements can be read from the z-axis but still i think it can be useful to some extent. maybe for altitude correction. but i also saw that yaw reading (x,y) is also weak. how do you think we can make it more sensitive? why are you considering Gumstix for better lcd display? there are cheap and simple displays are awailable for Arduino. i even saw an old Nokia 3110 display attached successfully to Arduino on the internet...

still brainstorming... lol..
wish you luck and success...
dincer
Comment by Andrea Salvatore on April 15, 2008 at 10:49am
Ciao Dincer,

as I told you the Nunchuck z-axis is almost unusable, or I've not been able to use it. But the x and y-axis are those that I used. If you uncomment "// printNunchuckData();" line you can see the reading and can see the values of the x and y-axis variation as you move the Nunchuck, and better understand how they are used then.

The Arduino can be attached to display but usually they are not that "graphic" oriented. Usually they are 1, 2, 4 text lines that can be used via serial or i2c protocol.

When I talk about a Gustix with LCD display I talk about a real LCD screen 4.3" wide with touchscreen overlay 16bit or 18bit colour.

Not to mention that the Gumstix can managed 2d and 3d graphics quite easily. That's a whole different thing, but I'm sure that'll start with something "simple" as an Arduino + 4 lines serial LCD screen that I already got at home.

But I'm preparing a more detailed post about that and there'll be more accurate in describing my controller project.

Cheers,

Andrea
Comment by dincer hepguler on April 16, 2008 at 7:14am
Andrea,
i just realized that the code you posted here is not the same as you havbe sent me... also this code gives errors while compiling... first include sentences are incomplete... some more errors.. pls check it out... :)

best wishes,
dincer
Comment by Andrea Salvatore on April 16, 2008 at 7:58am
Dincer,

thanks there was a problem when pasting code. An "<" is interpreted as an HTML tag an not as a "minor" operand :)

Now it should be ok and the same code you got.

Please check. Thanks!

Andrea
Comment by Craig on April 16, 2008 at 12:06pm
Andrea,

Very nice design. I am interested in mounting a similar system for aerial herd checks. I like the feature of locking the camera in place. How would you suggest mounting the system in such a way where the aircraft can still maneuver but keeping the video locked on a fixed location?

Thanks,

Craig
Comment by Andrea Salvatore on April 16, 2008 at 12:29pm
Craig,

the lock inplace has been implemented as at first the pan&tilt camera was meant to be installed on a qudricopter, so able to stand still (almost) at a certain position. And in that situation the "simple" lock of the camera does the trick.

But for airplanes it's totally different. You want a "lock on target" and it's definetly not an easy thing to do with cheap equipment.

But if I'd have a low budget to implement something similar you have to do use a different equipment.

First you have to put a 360° servo at the base (for panning). If you think to install the mechanism at the bottom of the airplane (best position for lock-on-target camera) you should do the same for tilting servos as well.

Second, you should use an intelligent camera. A programmable one, as the CMUCam3 for example. Face recognition/following algoritms has been already developed and I think it can be possible to do the same for a lock-on-target one at certain conditions for the target, as colour, speed etc.

It would be very interesting to develop such a system. I'm not going to do for my UAV, not for now :)

Hope to have helped you and if you decide to develop something similar let me know, and let me know how I can help you,

Andrea
Comment by Craig on April 16, 2008 at 2:02pm
Andrea,

Appreciate the response! I will definitely let you know. And if you have any other suggestions on good video/still cameras (and if any have decent zoom capability), please let me know. I'm currently looking into ways to automatically identify herd animals in various terrain and zoom in to conduct herd counts as well as basic physical assessments. Cheap is good, but for my own learning curve, any info would help. I have only basic electronics and programming experience...most of my experience is in health, veterinary medicine, and web-based applications.

Thanks again!

C

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2014   Created by Chris Anderson.

Badges  |  Report an Issue  |  Terms of Service