ArduinoGeneral

Using XBEE on Relay Shield v2.1?

userHead testnia 2014-11-17 01:23:13 3651 Views7 Replies
Hi, I am unable to get the XBee running on my relay shield. There seems to be no tutorial on it on the wiki. A quick search here showed someone once posted a sample code, but the link has long expired.

If anyone could provide a simple example on communicating between two separate xbee that will be fantastic. Also, im wondering if there are hardware modifications that needs to be done on the board to allow that xbee to work or will the xbee work solely by simply plugging it into the holder.

Much Appreciated.

2014-11-19 10:08:52 What is your hardware connection? Could you attach a photo?

If you want to use software serial port,  you need to connect xbee to the software serial.
[code]if (XBee.available()) //Reads and prints on serial monitor data enter in XCTU.
    Serial.write(XBee.read());
  if (Serial.available()) //Sends data entered into serialmonitor through XBEE.
    XBee.write(Serial.read()); [/code]

This code will print what SoftwareSerial "received", not  "transmit". So the hardware serial port will only output "Goodnight moon!", because there is nothing in the SoftwareSerial port.

But there is a problem that the shield xbee socket is hardware connecting to RX & TX. It can't be changed.
userHeadPic Grey.CC
2014-11-18 20:23:33 [quote="Grey"]
Hello testnia,

Could you check your xbee communication baudrate? It should be same with the sketch.
For example, if my xbee baudrate is 9600, I have to modify the code baudrate to 9600.
And you could write a simple code to test it:

[code]void setup() 
{
Serial.begin(9600); // change the baudrate to your xbee one
}

void loop() // run over and over
{
Serial.println("Goodnight moon!");
delay(1000);
}[/code]
[/quote]

Okay the xbee works if use a simple "Serial.print". However I am unable to emulate the result using software serial. Any idea how I can enable softserial to work with the XBee?

This is what i have drafted up.
[code]AltSoftSerial XBee(8, 9); // RX, TX //Enable a separate serial monitor

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  XBee.begin(9600);
  XBee.println("Hello, world?"); //Test line, this does not show on XCTU nor serial monitor
 
}

void loop() // run over and over
{
 
  Serial.println("Goodnight moon!");  //This line appears on BOTH xctu and serial monitor

  delay(1000);
  if (XBee.available()) //Reads and prints on serial monitor data enter in XCTU.
    Serial.write(XBee.read());
  if (Serial.available()) //Sends data entered into serialmonitor through XBEE.
    XBee.write(Serial.read());

}[/code]
userHeadPic testnia
2014-11-18 10:55:40 Hello testnia,

Could you check your xbee communication baudrate? It should be same with the sketch.
For example, if my xbee baudrate is 9600, I have to modify the code baudrate to 9600.
And you could write a simple code to test it:

[code]void setup() 
{
Serial.begin(9600); // change the baudrate to your xbee one
}

void loop() // run over and over
{
Serial.println("Goodnight moon!");
delay(1000);
}[/code]
userHeadPic Grey.CC
2014-11-17 22:34:45 [quote="Grey"]
Hi,

Could you attach a photo about hardware connection?
There is a switch "Run/Prog" on the board, please turn it to the "Run" side.
And what is your microcontroller? UNO? or Leonardo? Xbee socket will connect hardware Serial port. So for UNO it is just "Serial", but for leonardo it is "Serial1".
And it is better to show me your code.
[/quote]

I'm simply using the stock SoftwareSerial example as I am not very experienced with this.

[code]/*
  Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

Note:
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

Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
[/code]

There is gibberish data that is reflected on the XCTU console (paired with another Xbee) when the code is uploaded on the UNO board.

[img]http://oi60.tinypic.com/rmqt1v.jpg[/img]
userHeadPic testnia
2014-11-17 18:37:20 Hi,

Could you attach a photo about hardware connection?
There is a switch "Run/Prog" on the board, please turn it to the "Run" side.
And what is your microcontroller? UNO? or Leonardo? Xbee socket will connect hardware Serial port. So for UNO it is just "Serial", but for leonardo it is "Serial1".
And it is better to show me your code.
userHeadPic Grey.CC
2014-11-17 15:28:35 [quote="Grey"]
Hello testnia,

It will request an external power supply to use Xbee on the shield. And there is indicator LED "ASSOC"
If everything is OK, it will be light, when you plug xbee on the shield.
[/quote]

Hi thanks for the apt reply, all the indicators are working.
However, I am still unsure how to enable the RX/TX pins of the xbee on the relay shield. Should I be using softwareserial? If you could provide a small sample on initializing/activating the serial communication of the xbee that will be great.
userHeadPic testnia
2014-11-17 11:58:15 Hello testnia,

It will request an external power supply to use Xbee on the shield. And there is indicator LED "ASSOC"
If everything is OK, it will be light, when you plug xbee on the shield.
userHeadPic Grey.CC