Xbee servo help

Ok can anyone help me???
I have 2 xbees and 2 arduinos
I have a servo and a potentiometer
I want to turn the potentiometer and have the servo turn with it wirelessly
Can anyone help me with the code for the sending Arduino and the receiving Arduino??
You will be credited

School project, huh? Too lazy to do any searching on your own, huh?

OK. Let's start with the basics.

1) Which XBees do you have? 2) Do you have them configured so that they can talk to each other? 3) How are they connected to the Arduinos? 4) Do you know how to read the potentiometer value? 5) Do you know how to properly attach the servo? 6) Do you know how to properly power the servo? 7) Do you know how to make the servo move? 8) Do you know how to use Serial.begin()? 9) Do you know how to use the map function? 10) Do you know how to use Serial.write()? 11) Do you know how to use Serial.available()? 12) Do you know how to use Serial.read()?

There are enough clues there for you to figure out how to do what you want to do.

Yes I no everything with the servos and the Xbee all I need elo with is the code I'm née to code and in new to wireless so many you could direct me in. A direction that has a good tutorial or help me yourself with some simple code Thank you

The XBees transmit everything that appears on the serial port, and put everything they receive over the air on the serial port.

So, to send data, use Serial.begin() to establish a serial connection, and Serial.print() or Serial.write() to send the data.

To receive data, use Serial.begin() to establish a serial connection, Serial.available() to see how much data there is to read, and Serial.read() to read the data.

It is up to you to determine what data it is meaningful to send, how to send it, how to receive it, and how to use what you have received.

So from there cna you just do the sending code and ill try and do the recieving. i have looked around and learned some more but am still some what stuck

This code will read the pot pin (assuming you connect the pot to pin 0) once a second, and send that value to the serial port.

int potPin = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
   int potVal = analogRead(potPin);
   potVal = map(potVal, 0, 1023, 0, 180);

   Serial.write(potVal);
   delay(1000);
}

So I have looked online with some of the general Xbee recording code and the receiving looks a lot harder then the. Sending could you please help me with the receiving

Will I get credit for this when you turn your homework in?

hahah yes your name will be all over it. you have helped me before and will get much credit this is actually for the colorado state science and engineering air

You should make one change to the sender. Change:

   potVal = map(potVal, 0, 1023, 0, 180);

   Serial.write(potVal);

to

   [glow]byte servoVal[/glow] = map(potVal, 0, 1023, 0, 180);

   Serial.write([glow]servoVal[/glow]);

The complex part about receiving data is generally in collecting the string into an array, and then parsing the string and converting that string back to an integer.

Since the sender is using Serial.write() to write a single byte, the complexity is avoided. The receiver code can look like this:

void setup()
{
   Serial.begin(9600);
}

void loop()
{
   if(Serial.available() > 0)
   {
      byte servoAng = Serial.read();

      // Send the servo to the position read... <-- you get to make this happen
   }
}

// Send the servo to the position read… ← you get to make this happen
}
}

When You say you get to make happen whta do you mean by that? Do i add something elts to the code?

When You say you get to make happen whta do you mean by that? Do i add something elts to the code?

No, the comment will do it all by itself.

Yes I no everything with the servos

Well, do you or don't you. You now have an angle that servo is to be positioned at. Make it so.

No, the comment will do it all by itself.

Damn it. Tea splattered all over the monitor.

well i want the servo to turn with the potentiometer.
Such as in this code:

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}

well i want the servo to turn with the potentiometer. Such as in this code

So, spend some time with this page: http://arduino.cc/en/Reference/HomePage Go through the last bit of code you posted, and figure out EXACTLY what each line is doing.

When you understand that, you'll know which two lines to copy and past into your receiver sketch, in place of the comment (which appears to not actually control the servo).

Hey Paul S i really need this code i have been busy soldering everything up and all of that and i really need your help. i am not good at coding and am very new to this. i really need your help for the code and will give you much deserved credit. If you could just finalize the sending code and complete the receiving code that would be great.

Thank You

Sender code:

int potPin = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
   int potVal = analogRead(potPin);
   byte servoVal = map(potVal, 0, 1023, 0, 180);

   Serial.write(servoVal);
   delay(1000);
}

Receiver code:

[glow]#include <Servo.h>

Servo myservo;  // create servo object to control a servo
[/glow]
void setup()
{
   Serial.begin(9600);
[glow]   myservo.attach(9);  // attaches the servo on pin 9 to the servo object[/glow]
}

void loop()
{
   if(Serial.available() > 0)
   {
    byte servoAng = Serial.read();

    // Send the servo to the position read... <-- you get to make this happen
[glow]    myservo.write(servoAng);[/glow]
   }
}

The highlighted code is all you needed to add (swiped from the code you posted) to actually make the servo move.

at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTXPort.nativeavailable(Native Method) at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532) at processing.app.Serial.serialEvent(Serial.java:215) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575) Error inside Serial.serialEvent() java.io.IOException: Bad file descriptor in nativeavailable at gnu.io.RXTX``

that was the error i get when i run the codes any ideas to fix them and both of my xbees for some reason are unabke to read but when i go into terminal they communicate with eachother