Skip to main content
Question Protected by VE7JRO
Fixed syntax highlighting, added tags.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

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);
#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?

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?

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?

Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link
Spencer Cook
Spencer Cook

Arduino Mega 2560 SoftwareSerial Not Working

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?