Pro SB2 modules giving me garbage on Serial.read()

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
frippe75
 
Posts: 33
Joined: Wed Aug 13, 2014 2:55 pm

Pro SB2 modules giving me garbage on Serial.read()

Post by frippe75 »

Code: Select all

void handleSerial() {
  char inData[20]; // Allocate some space for the string
  char inChar; // Where to store the character read
  byte index = 0; // Index into array; where to store the character
  
  while (Serial.available() > 0) {
       if(index < 10) {
           in = Serial.read(); // Read a character from Xbee connected to hardware serial
           data[index] = in; 
           index++; 
           data[index] = '\0'; // Null terminate the string
       }
   }
   if (index > 0) {
       Serial.print("handleSerial:"); 
       Serial,println(data); // Sent back via Xbee on hardware serial
   }
}

void loop()  {
    handleSerial();
}

The code above runs on a Arduino FIOv3.
Both Xbee and Serial.begin sets the baud to 115200. Xbee running in AT mode.
The other Xbee is connected via a FTDI cable to my laptop running Processing application. Also 115200.

All data going from the FIO -> Laptop arrives correct. I'm parsing GPS data and other sensor data which is printed fine!.

BUT!

When I try to send more than one consecutive character from Processing (laptop) -> FIO (i.e string) it seems to get "corrupted".
The handleSerial function simply loops the incomming string backs to the laptop.

Corrupted output observed on the laptop:
handleSerial: 'G'�'

Code on the laptop for sending the data in the first place:

Code: Select all

if(button == gpsButton && event == GEvent.CLICKED) {
    if (xbeePort != null)  
      xbeePort.write("G:T");
    
  }

From processing write() API :
Description Writes bytes, chars, ints, bytes[], Strings to the serial port


Initially thought the ":" could be something I needed to escape but even "AA" would get corrupted.
It looks like the write() does not handle strings. Tried make consecutive write() calls one character at a time...

Another thought is that this has something to do with the FIO itself... Connecting the FIO Xbee to a Windows system running X-CTU works... So that basically tells me the processing part is out of the equation.... Read some threads about FIO needing 57400 baud for programming but it looks like (to me) this is only during programming....

ANY suggestions, please!! :-)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Pro SB2 modules giving me garbage on Serial.read()

Post by adafruit_support_rick »

Have you tried running everything at a lower baud rate? Does that change the problem at all?

User avatar
frippe75
 
Posts: 33
Joined: Wed Aug 13, 2014 2:55 pm

Re: Pro SB2 modules giving me garbage on Serial.read()

Post by frippe75 »

Ok! I will try that tomorrow and post an update shortly after.
Thx!

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”