combabuld serial output with communication through xbees

Parallax 32408 XBee ZigBee Pro 60 mW Wire Antenna, Series 2 (XBP24-Z7WIT-004)

i have the baud rate at 9600 on both xbee and made sure its the same on the aduino. it seems to be mostly with my joystick values not sure if i up the baud rate would that help? heres my code just in case

tx

/*
 Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
 For more information visit my blog: http://blog.tkjelectronics.dk/ or
 send me an e-mail:  kristianl@tkjelectronics.com
 */
#include <PS4BT.h>
#include <usbhub.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode
//PS4BT PS4(&Btd, PAIR);
// After that you can simply create the instance like so and then press the PS button on the device
PS4BT PS4(&Btd);

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial xbee(5, 4); // TX, RX
int LYVALUE;
int LXVALUE;
int oldLYvalue;
int oldLXvalue;
int RYVALUE;
int RXVALUE;
int oldRYvalue;
int oldRXvalue;
int oldCvalue;
int oldDvalue;
int angleC = 96;
int angleD = 90;
int Forward;
int Backward;
int Movement;
int oldmove;
const byte numChars = 32;
char *msgForRx = "";
char *oldmsgForRx = "";
boolean Frwrd = false;
boolean Bkwrd = false;
bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;
char receivedChars[numChars];
char tempChars[numChars];
char messageFromRx[numChars] = {0};
boolean newData = false;
boolean connection = false;
int tick = 0;
int timeout = 0;
int oldtimeout = 0;

void setup() {

  Serial.begin(9600);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); // Halt
  }
  Serial.print(F("\r\nPS4 Bluetooth Library Started"));
  xbee.begin(9600);
}
void loop() {
  Usb.Task();

  if (PS4.connected()) {
    if (PS4.getAnalogHat(LeftHatX) || PS4.getAnalogHat(LeftHatY) || PS4.getAnalogHat(RightHatX) || PS4.getAnalogHat(RightHatY))
    {
      //Stick Values
      LYVALUE = PS4.getAnalogHat(LeftHatY);
      LYVALUE = map(LYVALUE, 0, 255, 130, 45);
      LXVALUE = PS4.getAnalogHat(LeftHatX);
      LXVALUE = map(LXVALUE, 0, 255, 39, 120);

      RYVALUE = PS4.getAnalogHat(RightHatY);
      RXVALUE = PS4.getAnalogHat(RightHatX);

    }

    //==================================================
    if (PS4.getAnalogButton(R2) != oldR2Value && !Bkwrd) {// Only write value if it's different
      oldR2Value = PS4.getAnalogButton(R2);
      Forward = PS4.getAnalogButton(R2);
      Forward = map(Forward, 0, 255, 88, 130);
      Frwrd = true;
      Movement = (Forward);
    }
    else {
      Frwrd = false;
    }
    //==================================================
    if (PS4.getAnalogButton(L2) != oldL2Value && !Frwrd) { // Only write value if it's different
      oldL2Value = PS4.getAnalogButton(L2);
      Backward = PS4.getAnalogButton(L2);
      Backward = map(Backward, 0, 255, 87, 45);
      Bkwrd = true;
      Movement = (Backward);
    }
    else {
      Bkwrd = false;
    }

    if (PS4.getButtonClick(PS)) {
      Serial.print(F("\r\nPS"));
      PS4.disconnect();
    }
    else {
      if (PS4.getButtonClick(TRIANGLE)) {
        msgForRx = "Triangle";
      }
      if (PS4.getButtonClick(CIRCLE)) {
        msgForRx = "Circle";
      }
      if (PS4.getButtonClick(CROSS)) {
        msgForRx = "Crosss";
        // PS4.setLedFlash(10, 10); // Set it to blink rapidly
      }
      if (PS4.getButtonClick(SQUARE)) {
        msgForRx = "Square";
        //PS4.setLedFlash(0, 0); // Turn off blinking
      }

      if (PS4.getButtonClick(UP)) {
        msgForRx = "Up";
        //PS4.setLed(Red);
      } if (PS4.getButtonClick(RIGHT)) {
        msgForRx = "Right";
        //PS4.setLed(Blue);
      } if (PS4.getButtonClick(DOWN)) {
        msgForRx = "Down";
        //PS4.setLed(Yellow);
      } if (PS4.getButtonClick(LEFT)) {
        msgForRx = "Left";
        //PS4.setLed(Green);
      }

      if (PS4.getButtonClick(L1))
        msgForRx = "L1";
      if (PS4.getButtonClick(L3))
        msgForRx = "L3";
      if (PS4.getButtonClick(R1))
        msgForRx = "R1";
      if (PS4.getButtonClick(R3))
        msgForRx = "R3";

      if (PS4.getButtonClick(SHARE))
        msgForRx = "Share";
      if (PS4.getButtonClick(OPTIONS)) {
        msgForRx = "Options";
        printAngle = !printAngle;
      }
    }
  }
  //pan
  if (RXVALUE < 40 && angleC >= 0 && angleC < 180 ) {
    angleC += 1;
  }
  if (RXVALUE > 160 && angleC > 0 && angleC <= 180) {
    angleC -= 1;
  }
  //tilt
  if (RYVALUE < 40 && angleD >= 0 && angleD < 180) {
    angleD += 1;
  }
  if (RYVALUE > 160 && angleD > 0 && angleD <= 180) {
    angleD -= 1;
  }
  delay(10);
   recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
    // this temporary copy is necessary to protect the original data
    //   because strtok() replaces the commas with \0
    parseData();
    if (strcmp(messageFromRx, "connected")  == 0)  // test to see if the two strings are equal
    {
      connection = true;
      timeout = 0;
    }
    delay(10);
    newData = false;
  }
  //checkconnect();
  if (Movement != oldmove || LXVALUE < (oldLXvalue - 1) || LXVALUE > (oldLXvalue + 1) || angleC != oldCvalue  || angleD != oldDvalue || msgForRx != oldmsgForRx) {
    Serial.print(F("<"));
    Serial.print(msgForRx);
    Serial.print(F(","));
    Serial.print(Movement, DEC);
    Serial.print(",");
    Serial.print(LXVALUE, DEC);
    Serial.print(F(","));
    Serial.print(angleC, DEC);
    Serial.print(F(","));
    Serial.print(angleD, DEC);
    Serial.println(F(">"));

xbee.print(F("<"));
    xbee.print(msgForRx);
    xbee.print(F(","));
    xbee.print(Movement, DEC);
    xbee.print(",");
    xbee.print(LXVALUE, DEC);
    xbee.print(F(","));
    xbee.print(angleC, DEC);
    xbee.print(F(","));
    xbee.print(angleD, DEC);
    xbee.println(F(">"));
    
    oldLXvalue = LXVALUE;
    oldLYvalue = LYVALUE;
    oldRXvalue = RXVALUE;
    oldRYvalue = RYVALUE;
    oldCvalue = angleC;
    oldDvalue = angleD;
  }
  msgForRx = "connected";
  oldmsgForRx = msgForRx;
  oldmove = Movement;
}
//=============
void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (xbee.available() > 0 && newData == false) {
    rc = xbee.read();
    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//============

void parseData() {

  // split the data into its parts
  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ",");     // get the first part - the string
  strcpy(messageFromRx, strtokIndx); // copy it to messageFromPC

}

//============

void showParsedData() {
  Serial.print(messageFromRx);
}

void checkconnect() {
  if (!connection && tick == 0) {
    Serial.println("Not connected");
    tick = 1;
  }
  if (!connection || timeout >= 40) {
    xbee.print("<");
    xbee.print("connected");
    xbee.print(",");
    xbee.println(">");
  }
  delay(10);
  if (connection && tick == 1) {
    Serial.println("Connected!");
    tick = 0;
  }
  delay(10);
  if (connection) {
    timeout += 1;
    oldtimeout = timeout;
    if (timeout >= 150) {
      connection = false;
      tick = 0;
    }
  }
}

rx

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial xbee(53,50); // TX, RX
Servo SteerServo, MotorServo, CamServoC, CamServoD;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
char messageFromTX[numChars] = {0};
char Buttoncheck[numChars] = {0};
boolean newData = false;
boolean connection = false;
int tick = 0;
int timeout = 0;
int oldtimeout = 0;
//ints for incoming servo data
int ServoA = 0;
int ServoB = 0;
int ServoC = 0;
int ServoD = 0;

int OldservC = 0;
int OldservD = 0;

//============
void setup() {
  Serial.begin(9600);
  xbee.begin(9600);
  MotorServo.attach(9);
  SteerServo.attach(6);
  CamServoD.attach(3);//tilt
  CamServoC.attach(5);//pan
}
//============

void loop() {
  recvWithStartEndMarkers();

  if (newData == true) {
    strcpy(tempChars, receivedChars);
    // this temporary copy is necessary to protect the original data
    //   because strtok() replaces the commas with \0
    parseData();
    void showParsedData();
    if (strcmp(messageFromTX, "connected")  == 0)  // test to see if the two strings are equal
    {
      timeout = 0;
      connection = true;
      xbee.print("<");
      xbee.print("connected");
      xbee.print(",");
      xbee.println(">");
    }
    delay(10);
    newData = false;
  }
  //checkconnect();
}



//============

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (xbee.available() > 0 && newData == false) {
    rc = xbee.read();
    Serial.print(rc);
    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//============

void parseData() {

  // split the data into its parts
  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ",");     // get the first part - the string
  strcpy(messageFromTX, strtokIndx); // copy it to messageFromPC

  strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
  ServoA = atoi(strtokIndx);     // convert this part to an integer

  strtokIndx = strtok(NULL, ",");
  ServoB = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ",");
  ServoC = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ">");
  ServoD = atoi(strtokIndx);

}

//============

void showParsedData() {
  Serial.print(messageFromTX);
  Serial.print(", ");
  Serial.print(ServoA);
  Serial.print(", ");
  Serial.print(ServoB);
  Serial.print(", ");
  Serial.print(ServoC);
  Serial.print(", ");
  Serial.println(ServoD);
}
void movement() {
  MotorServo.write(ServoA);
  SteerServo.write(ServoB);
  if (ServoC > 0 && ServoC < 180 && ServoC != OldservC)
  {
    CamServoC.write(ServoC);
    OldservC = ServoC;
  }
  if (ServoC > 0 && ServoC < 180 && ServoD != OldservD) {

    CamServoD.write(ServoD);
    OldservD = ServoD;
  }
}
void Functions() {

  if (strcmp(messageFromTX, "Options")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Share")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "R3")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "L3")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "L1")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "R1")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Left")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Right")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Up")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Down")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Square")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Cross")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Circle")  == 0)  // test to see if the two strings are equal
  {

  }
  if (strcmp(messageFromTX, "Triangle")  == 0)  // test to see if the two strings are equal
  {

  }

}
void checkconnect() {
  if (!connection && tick == 0) {
    Serial.println("Not connected");
    tick = 1;
  }

  delay(10);
  if (connection && tick == 1) {
    Serial.println("Connected!");
    tick = 0;
  }
  delay(10);
  if (connection) {
    timeout += 1;
    oldtimeout = timeout;
    if (timeout >= 100) {
      connection = false;
      tick = 0;
    }
  }
}

combabuld?

Pete

ÉË«W%%KLš,1rù)<connected,0,0,176,170>
<connected,0,0,177,171>
¹�•±b‚bŠºÂbŠº’òj
<connected,0,0,179,173>
<connected,0,0,180,174>
<connected,0,0,180,175>
<con•�Ñ•‚bjü<connected,0,0,180,177>
<connected,0,0,180,178>
¹Ñ±0,0,180,179>
<connected,0,0,180,180>

thats the raw data it doesnt show anything if i only show parsed data

while (xbee.available() > 0 && newData == false) { rc = xbee.read(); Serial.print(rc);