Go Down

Topic: Xbee Serial Communication Problem (Read 108 times) previous topic - next topic


Hey guys

i got some kind of a problem with my xbee arduino uno setup.

I have a flex sensor attached to one Arduino Xbee and a servo motor at another Arduino Xbee Combination.

Now the Xbees communicate fine but the Serial Putput from one Arduino doesnt match the receiving side.

i attached program and serial output.

Greetings Exilant


Your transmitting arduino is transmitting between one and three characters as the servo position command. Your receiving arduino is trying to use each individual character as the position command. You need to capture all the command bytes and convert to an number, then send that to the servo. Some servo test code you can try with the serial monitor to see how it works.

Code: [Select]

//zoomkat 3-5-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {

  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-delomit-test-22-dual-input"); // so I can keep track of what is loaded

void loop() {

  //expect a string like 700, or 1500, or 2000,
  //or like 30, or 90, or 180,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
          Serial.print("writing Microseconds: ");
          Serial.print("writing Angle: ");

        //do stuff with the captured readString
        readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


okay thx i will implement it asap and get back to u if it worked

Go Up