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!
Xbee communication errors
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Xbee communication errors
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 ). It is likely that you are storing some sort of binary number instead of the character you think you are storing.
-
- Posts: 12
- Joined: Sun Dec 27, 2009 11:48 pm
Re: Xbee communication errors
Here's the code:
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.
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);
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Xbee communication errors
The problem is here:
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.
Code: Select all
if (Serial.available()) {
Serial.println((char)Serial.read());
inByte = (char)Serial.read();
Serial.println(inByte);
The good character will always go to the serial monitor, and the -1 character will always be used to control your LED.
-
- Posts: 12
- Joined: Sun Dec 27, 2009 11:48 pm
Re: Xbee communication errors
Fixed! Thank you very much!
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Please be positive and constructive with your questions and comments.