Xbee communication errors

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
bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Xbee communication errors

Post by bulmung »

At the NY Maker Faire I won an xstick(http://store.digi.com/index.cfm?fuseact ... ct_ID=1273) and have been interested in playing around with xbees so I ordered the 1mW series 1 xbee and the usb adapter.

I got them communicating but when I go to create a variable from the serial read on the arduino it stores the same letter (y with dots over it) but the serial is receiving the correct message. So for instance, when I send "i" over hyperterminal the arduino receives the "i" and stores the "y". I am able to fix this however by sending two letters in quick succession with the second being the one I want it to store.

Is there some way to fix this?
Thanks!

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

Re: Xbee communication errors

Post by adafruit_support_rick »

It would help to see your code, and some sample output. The "y with dots over it" signals a non-printable character (not to be confused with the unprintable words you no doubt uttered when the problem first occurred :D ). It is likely that you are storing some sort of binary number instead of the character you think you are storing.

bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Re: Xbee communication errors

Post by bulmung »

Here's the code:

Code: Select all

char inByte;


void setup()  {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  Serial.println("Connected");
}

void loop()             
{

if (Serial.available()) {
      Serial.println((char)Serial.read());
  inByte = (char)Serial.read();
  Serial.println(inByte);
  if (inByte == 'i')
  {
    digitalWrite(13, HIGH);
  }
  if (inByte == 'o')
  {
    digitalWrite(13, LOW);
  }
}
  delay(1000);
}
This is the output, first typing just one letter than two letters quickly, the first shows whats received over serial, the letter after shows whats stored.
Image

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

Re: Xbee communication errors

Post by adafruit_support_rick »

The problem is here:

Code: Select all

if (Serial.available()) {
      Serial.println((char)Serial.read());
  inByte = (char)Serial.read();
  Serial.println(inByte);
You are calling Serial.read() twice. If there is only one character available, the second call to Serial.read() will return -1 (which prints as the dotted 'y').

The good character will always go to the serial monitor, and the -1 character will always be used to control your LED.

bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Re: Xbee communication errors

Post by bulmung »

Fixed! Thank you very much!

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

Re: Xbee communication errors

Post by adafruit_support_rick »

cool! :)

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

Return to “XBee products (discontinued)”