Home/Support/Support Forum/XBee series 2 AT mode and 2 arduinos

XBee series 2 AT mode and 2 arduinos

0 votes
I have 2 xbees series 2 and have them configured to send information back and forth so I wanted to use a pot and servo and I am about to send values and read them using XCTU. The numerical values show on the the receiving xbee. When I connect it to the arduino I am getting -1 and thats the only thing I receive. I know there has to be an easy solution.

Thanks in advance for any help

Transmit Code

int potPin = 0;
#include <XBee.h>

XBee xbee = XBee();
void setup() {
// Serial port enable
Serial.begin(9600);
xbee.begin(9600);
}

void loop() {


// remap values from the analogValue5 variable to 0 / 255
int val = map(analogRead(potPin), 0, 1023, 0, 9);

// send the value to the serial port
Serial.print(val);
xbee.send(val);
delay(50);

}

Receive Code

#include <Servo.h>

int servoPin = 9;
Servo myservo;
void setup() {
Serial.begin(9600);

myservo.attach(servoPin);

}

void loop() {

while(Serial.available()>0);

int data = Serial.read();
int pos = map(data, 0, 9, 0, 180);
pos = constrain(pos, 0, 180);

myservo.write(pos);

Serial.println(data);
Serial.flush();
}
asked Jun 22, 2015 in RF Solutions and XBee by sjb New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
I believe this is a duplicate post. If not, please state so.
answered Sep 4, 2015 by mvut Veteran of the Digi Community (14,334 points)
...