Xbee communication errors

Xbee projects like the adapter, xbee tutorials, tweetawatt/wattcher, etc. purchased at Adafruit

Moderators: adafruit_support_bill, adafruit

Xbee communication errors

Postby bulmung » Fri Oct 05, 2012 9: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 10:48 pm

Re: Xbee communication errors

Postby adafruit_support_rick » Fri Oct 05, 2012 10: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.
User avatar
adafruit_support_rick
 
Posts: 2905
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Xbee communication errors

Postby bulmung » Sat Oct 06, 2012 4:05 pm

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

Re: Xbee communication errors

Postby adafruit_support_rick » Sun Oct 07, 2012 10:29 am

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.
User avatar
adafruit_support_rick
 
Posts: 2905
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Xbee communication errors

Postby bulmung » Sun Oct 07, 2012 10:49 am

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



Return to XBee products from Adafruit

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]