Wii Nunchuck and pan/tilt servo control

Hi again,
Aside from the CNC dream I have in my other post, I have this little fun device going... Its a pan and tilt setup I ordered from Robot Turrets. It was less than $30 and came with 2 servos.

I found in the forum a guy who wrote some pretty slick code for controlling the servos with the Wii nunchuck here:http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1197610037

He wrote it a year ago, and kinda stopped talking about it in his blog. It looks like hes moved on to a sick auto pilot project, so I can see why hes not messing with this anymore. I tried to contact him, but he has not emailed me back yet.

Anyway, I am really new at all of this and I have a few questions about this code. I know its way over my head...

First: It seems that I dont get full range of motion in either direction.

Second: The vertical axis is reversed, and I cant seem to find in the code where it calls for that.

Last: If you press and hold both the "C" and "Z" buttons together you can control with the joystick, where is the code is that? or is it a bad wire job?

Here is the video I posted

I will post some pics in a few.

Here is the code
http://www.jmaginary.com/wiiNunchuck.cpp.txt

Thanks in advance

Dave

Quote"Last: If you press and hold both the "C" and "Z" buttons together you can control with the joystick, where is the code is that?"

That is here, its down far in the code. I'll get to your other problems when i look at it some more

myWiiNunchuck.ReadDataFromNunchuck();
float xAnalogPos, yAnalogPos;
if( myWiiNunchuck.zButtonDown && myWiiNunchuck.cButtonDown )
{
xAnalogPos = ( myWiiNunchuck.GetXAnalog()+totalLastXAnalogPos )/(float)(smoothingLevel+1);
yAnalogPos = ( myWiiNunchuck.GetYAnalog()+totalLastYAnalogPos )/(float)(smoothingLevel+1);
}
else
{
xAnalogPos = ( min(max(myWiiNunchuck.GetXAccel()*1.25f, -1.0f), 1.0f)+totalLastXAnalogPos )/(float)(smoothingLevel+1);
yAnalogPos = ( min(max(myWiiNunchuck.GetYAccel()*1.5f, -1.0f), 1.0f)+totalLastYAnalogPos )/(float)(smoothingLevel+1);
}

hey myersweb -
I'd like to duplicate that. Do you have a wiring diagram that you used with the recycled code?
thanks

Sure, give me a few minutes to snap a photo.

Dave

Heres a crude wire diagram.. And a little more info on the program.

It has 7 levels of "smoothing" the level increases with every push of the "C" button. I have replaced one of the smoothing leds with a laser pointer. The "Z" button turns the smoothing off one level at a time.

The laser pointer was about the size of a pencil and only a few inches long. I took it apart and bypassed the switch so it was always on.

nice. thanks very much for sketching that out. I'm going to try and put it together this weekend.

I'd just like to thank the OP for the idea and sketching out the schematic. I put this together last night for fun, and already have some ideas.

I had a quick look at the code and made a few changes to correct the reverse pitch axis and rotation distance.

  if( myWiiNunchuck.cButtonDown && ( myWiiNunchuck.zButtonDown != myWiiNunchuck.cButtonDown ) )
    pitchServo.SetRotation(-(pitchServo.GetCurrentRotation()));
  else
    pitchServo.SetRotation(-(yAnalogPos));

(reversing rotation angle at time it is sent to servo)

 ServoControl(int pin, int neutral = 1500, int range = 800) : (extends the range of motion on the servos. On mine, both axis go the full swing in one direction, but only about 80% to the other)

Hope this helps some people.

I'm using this sketch to make a wii controlled water shooter. My nunchuck was giving me opposite movement for yaw (x) so fixed it with this small change to the code

yawServo.SetRotation(-xAnalogPos);

I need just one level of smoothing (equivalent to level 3 in this sketch) and always on, as I need the c and z buttons for other functions. Any suggestions how to do this?

could someone repost the arduino code from the beginning? the link from the first post is dead?

I no longer have the original code but my version of it ended up here:

what about the original code from the setup that myersweb uses? He got great control of the servos with multiple settings for smoothing etc.

good

Could the pan/tilt code also be implemented for use on an rc plane...maybe with some transmission with Xbee?