Go Down

Topic: [SOLVED] Cannot receive data from XBee+Arduino (Read 4223 times) previous topic - next topic

Akira_Hayasaka

Oct 26, 2012, 10:16 am Last Edit: Oct 26, 2012, 11:53 am by Akira_Hayasaka Reason: 1
Hello.

Could someone tell me how to receive data from XBee on Arduino?
I can send data but cannot receive, and totally get lost...

My enviroments.
- Arduino Leonardo
- XBee Series 2
- XBee Interface Board from digi http://strawberry-linux.com/images/xbee-wifi-kit_3.jpg
- XBee Explorer Regulated https://www.sparkfun.com/products/9132
- XBee Breakout Board http://www.switch-science.com/products/detail.php?product_id=100
And attach .pro files for both coodinator and router.

My sketch.
Code: [Select]
#include <SoftwareSerial.h>

uint8_t pinRx = 4, pinTx = 5;
SoftwareSerial mySerial(pinRx, pinTx);

long BaudRate = 9600;

int led = 12;

void setup()
{
 pinMode(led, OUTPUT);
 
 Serial.begin(BaudRate);
 mySerial.begin(BaudRate);  
 mySerial.listen();
}

void loop()
{
 // transmit
 if (Serial.available())
 {
   char gotChar = Serial.read();
   Serial.print(gotChar);
   mySerial.print(gotChar);
   digitalWrite(led, HIGH);
   delay(20);
   digitalWrite(led, LOW);
 }
 
 // receive
 if (mySerial.available())
 {
   char gotChar = mySerial.read();
   Serial.print(gotChar);
   digitalWrite(led, HIGH);
   delay(20);
   digitalWrite(led, LOW);    
 }
}



And my results.

Case. 1 : Both XBee can send and receive.
"X-CTU-Interface Board-XBee" -> "XBee-Interface Board-CoolTerm"
Success.
"X-CTU-Interface Board-XBee" <- "XBee-Interface Board-CoolTerm"
Success.

Case. 2 : XBee on Arduino side cannot receive message.
"X-CTU(or CoolTerm)-Interface Board-XBee" -> "XBee-Explorer Regulated-Arduino"
Fail. And no LED blink on 12 pin. But Explorer's RSSI light is ON and DOUT light is blinking.
"X-CTU(or CoolTerm)-Interface Board-XBee" <- "XBee-Explorer Regulated-Arduino"
Success.

Case. 3 : XBee on Arduino side cannot receive message.
"X-CTU(or CoolTerm)-Interface Board-XBee" -> "XBee-Breakout Board-Arduino"
Fail. And no LED blink on 12 pin.
"X-CTU(or CoolTerm)-Interface Board-XBee" <- "XBee-Breakout Board-Arduino"
Success.


Since I can send and receive with Interface Board, I think the XBee settings are OK.
RSSI right ON when I receive, so seems Arduino failed to retrive serial from XBee.
hmm :(

I appreciate any advice.
Thank you in advance!

A

nickgammon

Code: [Select]

  // transmit
  if (Serial.available())
  {
    char gotChar = Serial.read();
    Serial.print(gotChar);
    mySerial.print(gotChar);
    digitalWrite(led, HIGH);
    delay(20);
    digitalWrite(led, LOW);
  }


Why do you call this "transmit" when it only operates when there is data to be received?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Akira_Hayasaka

Thank you for the response!

This "transmit" get data from Serial Monitor on Arduino IDE.
I manually type chars on Serial Monitor and push "send" button.
Then "transmit" send that data to destination XBee via 5 pin which is defined as SoftwareSerial TX.
So the Serial.print() here is just for debug purpose.

The "receive" is get data from another XBee via 4 pin which is defined as SoftwareSerial RX.
Then pint it on Serial Monitor and blink LED for debug.
(But I never get any data, so this is my topic...)

A

Akira_Hayasaka

#3
Oct 26, 2012, 11:51 am Last Edit: Oct 26, 2012, 11:55 am by Akira_Hayasaka Reason: 1
agggghh!

I changed Leonardo to Uno, I can receive data!
What's happened to Leonardo's SoftwareSerial...?

Thanks!

nickgammon

Pins D4 and D5 on the Leonardo do not seem to support pin change interrupts and thus cannot be used with SoftwareSerial.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Akira_Hayasaka

#5
Oct 27, 2012, 03:36 am Last Edit: Oct 27, 2012, 03:37 am by Akira_Hayasaka Reason: 1
Hmm
Seems D8, D9, D10 and D11 works for SoftwareSerial on Leonardo.

nickgammon

Yes, because they are all marked "PCINT" on the schematic (pin change interrupt).


Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Akira_Hayasaka

Oh I see!

- SoftwareSerial needs pin change interrupt http://www.arduino.cc/playground/Main/PinChangeInt
- I just happened to set D5 as SoftwareSerial TX,
- and Uno has D5 with PCINT (D5 and D8-D13).


I should study schematics :)

Thank you so much!

PaulS

Quote
I should study schematics :)

Don't feel bad. I learned something new today, too.
The art of getting good answers lies in asking good questions.

Go Up