Arduino Mega 2560 Software Serial Not Working

Hello!

We have an xBee Pro S2C that is using this library (GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode) very well on a Software Serial connection to ports 2 and 3 on an Arduino Uno. However, when we take the same setup and try it on a Arduino Mega 2560 using any of the ports specified here:

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, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

We cannot get this setup to work on the Arduino Mega 2560. We did not try every combination of these ports but tried most of them and it continues to fail. We can get successful packets on an Uno on pins 2 and 3.

Code is as follows:

`#include "Arduino.h"
#include "XBee.h"
#include <SoftwareSerial.h>
#define IS_STAR 0
#if IS_STAR
#define rxPin 10 //input
#define txPin 11 //output
#else
#define rxPin 2 //input
#define txPin 3 //output
#endif
#include "SoftReset.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///setup xbee object

XBee xbee = XBee();
SoftwareSerial xBeeSerial = SoftwareSerial(rxPin, txPin);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Setting up class & contructors

Laser::Laser () {

pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
xBeeSerial.begin(9600);
xbee.setSerial(xBeeSerial);
Serial.begin(9600);`

Any thoughts as to why this might not work on a Arduino Mega?

Can you not use one of the actual hardware serial ports?

  xbee.setSerial(Serial2);

MorganS,

Thanks for your quick reply! Yes, we thought of that as well and tried but continues to fail. We tried all three hardware serial options (Serial1, Serial2, Serial3) with their respective pins.

Right now we have directly soldered and plugged in the pins to each port on the Mega to the xBee. We recently even tried a SparkFun xBee shield that we know is working on an Uno and that failed on the Mega as well. Perhaps just a bad Mega? Brand new out of the box!

Thanks for any help and suggestions!

Show a schematic. Show some code.

Can you define more precisely what failed when you tried to use the hardware serial? Could you see if it was a problem sending or receiving?