Search code examples
serial-portarduinoxbee

Xbee communication from Computer to Arduino - SoftwareSerial Pins


I'm trying to set up a wireless communication between a Computer (coordinator) and a Arduino Mega (router) using two xbees.

Here is the Coordinator configuration: ZIGBEE COORDINATOR AT Serial high:13A200 and serial low: 407B69E6

PAN ID: 1111
DH: 13A200
DL: 40813BFC (Rooter serial number low)
Baud Rate: 9600

Here is the Router Configuration: ZIGBEE ROUTER AT Serial high:13A200 and Serial low: 40813BFC

PAN ID: 1111
DH: 13A200
DL: 407B69E6 (Coordinator serial number low)
Baud Rate: 9600

I'm using the Xbee Explorer Regulated to connect the Xbee module to the board and the USB explorer board to connect the xbee to the computer. I'm able to communicate from the Arduino to the Computer. All data sent from the serial monitor of the Arduino IDE are received in the terminal window of XCTU. If I switch the modules I am still able to communicate.

Arduino Code

#include <SoftwareSerial.h>

uint8_t pinRx = 4 , pinTx = 2; // the pin on Arduino
long BaudRate = 9600;
char GotChar, getData;
SoftwareSerial xbee(pinRx, pinTx);

void setup() 
{
  Serial.begin(9600);
  Serial.println( "Welcome to the XBee Communication Test" );
  Serial.print("BaudRate:");
  Serial.println(BaudRate);
  Serial.print(" Rx Pin#");
  Serial.println(pinRx,DEC);
  Serial.print(" Tx Pin#");
  Serial.println(pinTx,DEC);
  xbee.begin( BaudRate );
  xbee.println("Setup Completed!");
}

void loop() 
{
  if (Serial.available()) 
  {
    GotChar = Serial.read();
    // Send it to Computer
    xbee.print(GotChar);
    // print it to serial monitor
    Serial.print(GotChar);
  }
  while (xbee.available()>0)
  {  
    //Serial.println("Ohohoh");
    getData = xbee.read();
    Serial.print(getData);
    // send it back
    xbee.println(getData);
  }
}

The problem

I can't send data from the computer to the arduino.

When I send a character from the computer using the XCTU terminal, the TX and the RSSI leds light up on the USB Explorer board. Same thing occurs on the Arduino, the DOUT and RSSI led light up and nothing is received. I have tried setting DH and DL to broadcast mode using 0 and FFFF as values for the coordinator but it didn't solve the problem.


Solution

  • I tought that the problem was related to the wiring so I double checked the circuit I was using. Then as TomLogic suggested I tried to establish another serial communication using pin 12 and 13. And finally I got these two modules working properly!

    The configurations for Coordinator and Router are correct and the Arduino code as well! Pin 4 can't be used with SoftwareSeria as RX.

    Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69