Hi, I'm new to Arduino/XBee use, and need some programming help.
I wish to control a pan-tilt mechanism (two servos) remotely. Input comes from a joystick on the Coordinator Arduino, and output is movement of two servos on the remote Router Arduino. I have successfully gotten the two XBees to talk with each other; that took a while. Also, I have been able to get the pan-tilt mechanism to work on a single Arduino using a joystick shield attached. So, the pieces are there.
Here is the code I'm using for the single Arduino control:
// Controlling a pan-tilt platform position (two servos) using the Sparkfun joystick shield
#include <Servo.h>
Servo vertservo; // create a vertical servo object to control vertical movement
Servo horzservo; // create a horizontal servo object to control horizontal movement
int potpinvert = 0; // analog pin 0 connects to vertical potentiometer in the joystick
int potpinhorz = 1; // analog pin 1 connects to horizontal potentiometer in the joystick
int val0; // variable to read the value from analog pin 0
int val1; // variable to read the value from analog pin 1
void setup()
{
vertservo.attach(9); // attaches the vertical servo on pin 9 to the vertical servo object
horzservo.attach(10); // attaches the horizontal servo on pin 10 to the horizontal servo object
}
void loop()
{
val0 = analogRead(potpinvert); // reads value of vertical pot (value between 0 and 1023)
val1 = analogRead(potpinhorz); // reads value of horiz pot (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scales vert pot value to the servo movement range
(Value between 0 and 180)
val1 = map(val1, 0, 1023, 0, 179); // scales the horz pot value to the servo movement range
(Value between 0 and 180)
vertservo.write(val0); // sets vertical servo position according to scaled value
horzservo.write(val1); // sets the horiz servo position according to the scaled value
delay(15); // waits for the servos to get to their commanded positions
}
My question is.....How do I get this program to work over the XBee network? From reading around in the Forum I'm suspecting that somehow I have to use a serial send command / serial read. I just don't know what I'm doing.
Any suggestions out there? Your help is GREATLY APPRECIATED! Tim