Memorial day is 05/25/2015 – Orders will ship out on May 26th. There will not be any deliveries or shipping on Monday. Any order placed after 11am ET on Friday May 22nd will not start to ship out until Tuesday May 26th.

Xbee communication errors
Moderators: adafruit_support_bill, adafruit

Xbee communication errors

by bulmung on Fri Oct 05, 2012 10:23 pm

At the NY Maker Faire I won an xstick(http://store.digi.com/index.cfm?fuseaction=product.display&Product_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!
bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Re: Xbee communication errors

by adafruit_support_rick on Fri Oct 05, 2012 11:33 pm

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.

adafruit_support_rick
 
Posts: 18369
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Xbee communication errors

by bulmung on Sat Oct 06, 2012 5:05 pm

Here's the code:
Code: Select all | TOGGLE FULL SIZE
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
bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Re: Xbee communication errors

by adafruit_support_rick on Sun Oct 07, 2012 11:29 am

The problem is here:
Code: Select all | TOGGLE FULL SIZE
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.

adafruit_support_rick
 
Posts: 18369
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Xbee communication errors

by bulmung on Sun Oct 07, 2012 11:49 am

Fixed! Thank you very much!
bulmung
 
Posts: 12
Joined: Sun Dec 27, 2009 11:48 pm

Re: Xbee communication errors

by adafruit_support_rick on Sun Oct 07, 2012 11:55 am

cool! :)

adafruit_support_rick
 
Posts: 18369
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY