problem with Arduino Uno and xbee shield

Hi guys,

I am using an Arduino Uno and i have connected an xbee shield on it. On the shield I have connected an xbee pro s2b module, which i have configured as router. I am going to use another xbee pro s2b that will be connected on a computer and configured as a coordinator. I ll create a mesh network between them.

My problem is that i keep getting the following errors when i try to upload the code on Arduino:
error: conflicting return type specified for ‘virtual void NewSoftSerial::write(uint8_t)’
error: overriding ‘virtual size_t Print::write(uint8_t)’
testing.ino: In function ‘void setup()’:
testing:24: error: no matching function for call to ‘XBee::setSerial(NewSoftSerial&)’
note: candidates are: void XBee::setSerial(HardwareSerial&)

My code is as follows:

#include <XBee.h>
#include <NewSoftSerial.h>

// Define NewSoftSerial TX/RX pins
#define ssRX 0
#define ssTX 1
NewSoftSerial nss(ssRX, ssTX);

//Create an XBee object
XBee xbee = XBee();

//Define the Destination address of the packets
XBeeAddress64 destaddress = XBeeAddress64(0x0013A200, 0x406F1997);

char Hello[] = "Hello World\n";

void setup()  
{
  Serial.begin(9600);
  nss.begin(9600);
  
  //We hook the XBee into the Software Serial
  xbee.setSerial(nss);
  
  Serial.println("Goodnight moon!");
}

void loop()
{
  Serial.println("in the loop");
  ZBTxRequest zbtx = ZBTxRequest(destaddress, (uint8_t *)Hello, strlen(Hello));
  xbee.send(zbtx);
  delay(1000);
}

This is the shield that I am using:
https://www.sparkfun.com/products/9841?

Regards,
gabys

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

The problem you are having is with compiling code, and has nothing to do with XBees and/or XBee shields.

What version of the IDE are you using?

Why are you trying to use software serial on the hardware serial pins? You can NOT do that.

I am using Arduino v1.0.3 IDE.

All the examples i found were using Software Serial for the xbee. What code should i write then to send my packets through the xbee?

Thank you in advance!

I am using Arduino v1.0.3 IDE.

Which is not compatible with NewSoftSerial.

All the examples i found were using Software Serial for the xbee.

SoftwareSerial, not NewSoftSerial.

What code should i write then to send my packets through the xbee?

The code you have is fine, if you use some other pins. If you want to use pins 0 and 1, use Serial (the instance of the HardwareSerial class).

I have the same shield. The shield uses either pins 0 and 1 or pins 2 and 3, depending on which position the switch is in. No other pins are used.

Paul, the above quote is something that you told me in another post.

In Arduino Uno, the pins 0 and 1 are used for the Serial, therefore i assume you can't use them for anything else. I have tried to move the shield 2 pins sideways (as there are 2 free pins on the board), but it was not feasible, the shield wouldn't fit correctly on the Arduino.

The way the shield is now connected on the Arduino, it uses the pins 0 and 1 for the RX and TX for the xbee.

Please correct me if I said something wrong as i am a newbie on these.

I have include the HardwareSerial.h file and tried to use the HardwareSerial class but i was getting an error on the following code:
HardwareSerial hs = HardwareSerial();
error: no matching function for call to 'HardwareSerial::HardwareSerial()'

And I have even tried to set the pins, although i am sure it is wrong because nowhere was the code written like this:
HardwareSerial hs = HardwareSerial(0, 1);
error: no matching function for call to 'HardwareSerial::HardwareSerial(int, int)'

You have also mentioned that the pins 2 and 3 can also be used, depending on which position the switch is in. For which switch are you referring to and in what position should i place it?

In Arduino Uno, the pins 0 and 1 are used for the Serial, therefore i assume you can't use them for anything else.

You can, but not at the same time you are using them for Serial.

I have tried to move the shield 2 pins sideways (as there are 2 free pins on the board), but it was not feasible, the shield wouldn't fit correctly on the Arduino.

Not surprising. What would have been surprising was if it had worked.

The way the shield is now connected on the Arduino, it uses the pins 0 and 1 for the RX and TX for the xbee.

That depends on which position the switch is in.

I have include the HardwareSerial.h file and tried to use the HardwareSerial class but i was getting an error on the following code:
HardwareSerial hs = HardwareSerial();
error: no matching function for call to 'HardwareSerial::HardwareSerial()'

There is an instance of the HardwareSerial class created, already. It is called Serial.

And I have even tried to set the pins, although i am sure it is wrong because nowhere was the code written like this:
HardwareSerial hs = HardwareSerial(0, 1);
error: no matching function for call to 'HardwareSerial::HardwareSerial(int, int)'

The ONE instance of the HardwareSerial class KNOWS which pins to use. The constructor for the HardwareSerial class does not need to be told which pins to use.

For which switch are you referring to

The only one on the shield.

and in what position should i place it?

The other position, obviously.

Hi Paul,

Sorry for the late reply, but I had to take care some other stuff. Basically, I found the switch you were talking about and changed its position and I have also tried to do some things based on the guidance you provided me.

The code you have is fine, if you use some other pins. If you want to use pins 0 and 1, use Serial (the instance of the HardwareSerial class).

So, I just modified the code to use the pins 2 and 3(based on the position of the switch), but now I get another error on the code.

Code:

#include <XBee.h>
#include <SoftwareSerial.h>

// Define SoftwareSerial TX/RX pins
#define ssRX 2
#define ssTX 3
SoftwareSerial nss = SoftwareSerial(ssRX, ssTX);

//Create an XBee object
XBee xbee = XBee();

//Define the Destination address of the packets
XBeeAddress64 destaddress = XBeeAddress64(0x0013A200, 0x406F1997);

char Hello = “Hello World\n”;

void setup()
{
Serial.begin(9600);
nss.begin(9600);

//We hook the XBee into the Software Serial
xbee.setSerial(nss);

Serial.println(“Goodnight moon!”);
}

void loop() // run over and over
{
Serial.println(“in the loop”);
ZBTxRequest zbtx = ZBTxRequest(destaddress, (uint8_t *)Hello, strlen(Hello));
xbee.send(zbtx);
delay(1000);
}

error: no matching function for call to ‘XBee::setSerial(SoftwareSerial&)’
note: candidates are: void XBee::setSerial(HardwareSerial&)

I really have no idea what went wrong there. I can’t define pins for the HardwareSerial since they are already being used by the Serial object (pins 0 and 1). I am starting to panic since it seems so simple and yet again clueless problems occur.

Regards,
gabys

You appear to have an older version of the XBee library than I have. Mine takes a Stream object as the argument to setSerial. Both HardwareSerial and SoftwareSerial derive from Stream.

Thank you Paul! I have tried several xbee.h libraries until i have found the correct one, but now the error is gone.

When I open my Serial Monitor i get the following output:

Goodnight moon!
in the loop
~ }3¢ @o -?ÿþ Hello World

Shouldn't the "Hello World" message be sent to the other xbee module rather than being displayed on the Serial Monitor?
I haven't modified my code so it can be viewed above.
I have checked the Serial No. of the receiving xbee and it is correct, it is the DH and DL that i wrote in the code.

I haven't wrote any code for the xbee module that receives the data, which is connected directly on the computer, but I used the x-ctu program to check for any incoming data through the Terminal tab.

Please note that the xbee connected on the computer is configured as Coordinator and the other xbee that is connected on the Arduino is configured as Router.

Shouldn't the "Hello World" message be sent to the other xbee module rather than being displayed on the Serial Monitor?

I would have expect so, but I've re-read your code. This is wrong.

//Create an XBee object
XBee xbee = XBee();

To create an instance of the class, you simply need:

XBee xbee;

You never call the constructor directly, as you are doing there. When you write something like

XBee *xbee = new XBee();

You are invoking the new operator, not calling the constructor of the class. The new operator is responsible for calling the constructor (the no-argument version, in this case, if there is more than one constructor defined), not you.

I don't know that that is your problem, but it should be fixed.

I am well aware of how classes work, but the examples I found were as I wrote it. Nonetheless, I tried what you told me. For “XBee xbee;” i get the same result, where for “XBee *xbee = new XBee();” i get the following errors:

In function ‘void setup()’: error: request for member ‘setSerial’ in ‘xbee’, which is of non-class type ‘XBee*’
In function ‘void loop()’: error: request for member ‘send’ in ‘xbee’, which is of non-class type ‘XBee*’

The second error is a follow up to the first one, but apart from that there was nothing different on the output of the code.