1

We have an xBee Pro S2C that is using this library (https://github.com/andrewrapp/xbee-arduino) 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:

*

https://www.arduino.cc/en/Reference/SoftwareSerial

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 "laser_essentials.h"
#include "XBee.h"
#include <SoftwareSerial.h>
#define IS_STAR 1
#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?

  • Does the Mega work at all? Can you flash an LED with it? – Roger Rowland Apr 19 '17 at 5:53
  • Yes, we have tried some basic sketches and all seem to perform fine on it. In addition, we have the same issue on a completely different Mega, so we must be doing something wrong. – Spencer Cook Apr 19 '17 at 20:08
  • 1
    Why use software serial in the first place? A Mega has multiple hardware serials. – gre_gor Apr 20 '17 at 18:02