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();
}
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");
}
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!! :-)