Keyboard >> Arduino Uno >> xbee >> Arduino Uno>> xbee >> servo

Hello all, I am a very beginnger and have a project which I want to control two servos wirelessly by using a keyboard (arrow keys) from my macbook pro. I have two codes for which the one arduino connected to pc and the other connected to the servos but I think something wrong and perhaps because of the code of the transmitter arduino code or I do not manage to work with the Processing code ??? Any help, suggesstion will be much aprreciated. By the way I am using Xbee s1 and they are working fine.

*************************************************** For the transmitter **************************************

char key = 0;
void setup() {

Serial.begin(9600);
}

void loop() {

if (Serial.available()) {
key = Serial.read();
if (key == byte(37))
{ // left
Serial.print("L");
delay(2000);
}

else if (key == byte(38))
{ // up
Serial.print("U");
delay(2000);
}

else
{
Serial.print("Z"); //doesn't matter what it is
}
}
}


***************************** Receiver Part, The one connected to the servos*************************

#include <Servo.h>

Servo myservo1;

int pos1 = 0;
int increment = 50;
int decrement = 50;

void setup() {

Serial.begin(9600);
myservo1.attach(10);

}

void loop() {
if (Serial.available()) {
int dataByte = Serial.read();
Serial.print(dataByte);

if(dataByte == 'L'){
pos1 = pos1 + increment;
myservo1.write(pos1);

}

else if(dataByte == 'U') {

pos1 = pos1 - decrement;
myservo1.write(pos1);
}

else //otherwise
{
pos1 = pos1 + 0;
myservo1.write(pos1);
}
}
}

*************************************************** Processing Code ************************

import processing.serial.*;
color fillVal = color(0,0,0);
Serial port;

void setup() {
size(100, 100);
println("Available serial ports:");
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
background(0,0,0);
if (keyPressed == true) {
fill(fillVal);
ellipse(50, 50, 50, 50);
}
else {
keyReleased();
}
}

void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
fillVal = color(255,255,255);
} else if (keyCode == DOWN) {
fillVal = color(255,0,0);
} else if (keyCode == LEFT){
fillVal = color(0,255,0);
} else if (keyCode == RIGHT) {
fillVal = color(0,255,150);
}
} else {
fillVal = 0;
}
port.write(keyCode);
if (keyPressed == false) {
port.write('0');
}
}

void keyReleased() {

}

Any ideas???

Thanks.

but I think something wrong

What is wrong is that have not posted near enough info. How are the XBees configured? How are they attached to the Arduinos?

By the way I am using Xbee s1 and they are working fine.

Your proof?

Sorry for lack of info. Xbees are attached on Xbee Shields and they are attached on Arduinos too. I know they are working fine because I tested them by doing a small example which I see on 三亚坏驹投资有限公司

Xbees are attached on Xbee Shields

Lovely.Which of the 1/2 dozen shields?

You should not be using Serial to talk to the XBee if you can avoid it. Leave Serial free for debugging. Use SoftwareSerial to talk to the XBee, if the shield supports it. If not, get a better shield.

In your "Keyboard >> Arduino Uno >> xbee >> Arduino Uno>> xbee >> servo", how is the second xbee going to generate control signals for the servo? I suggest you start with "Keyboard >> Arduino Uno >> servo" first and get that working, then add the xbee. Also #7 below will help you get started.

http://forum.arduino.cc/index.php/topic,148850.0.html

Firstly, I think I made a mistake. It must be "Keyboard >> Arduino uno >> xbee shield >> xbee s1 >> xbee s1 >> xbee shield >> arduino uno >> servo. If there is no uncertainty, what I am trying to say is that how I do create a keyboard (attached to my mac pro) input (arrow keys) on to the arduino connected to pc and send that input signal to the other arduino connected to the servo by using xbee s1 attached on xbee shield which is also attached to ardunio uno? What must be the procedure (Correction on the code, procedure for working with Processing and Arduino-Xbee etc.) I hope I make myself clear.

Thanks.