0

Apologies if this a relatively simple question, but I am rather new to Arduino's and cannot seem to find any concise information on the topic.
This is my XBee, mounted on a shield and placed onto a MEGA 2560. I want to leave Serial for USB debugging and use the Serial1 for XBee communication. enter image description here

Just to confirm, the two XBee's do communicate if I use SoftwareSerial. This is the code that works using SoftwareSerial:

#include <SoftwareSerial.h>

// XBee's DOUT (TX) is connected to pin 10 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 11 (Arduino's Software TX)
SoftwareSerial serial1(10, 11); // RX, TX
boolean nextLine = false;
void setup() 
{
  Serial.begin(9600);
  serial1.begin(9600);
}

void loop() 
{
   while(serial1.available()){ // there is data being sent from the xBee
    char read = char(serial1.read());
    if(read == 'A'){
      //Where ~ is the EOT character
      serial1.write("55.134~");
    }
  }
}

How do I communicate using Serial1?

2

If you take a look at the headers on the Mega, you'll notice that one of them has labels of "RX1" and "TX1" through "RX3" and "TX3". You'll also notice that the XBee shield does not connect to that header, therefore you cannot use Serial1 through Serial3 with the shield. Either switch to a breakout board that you can connect manually or stick to software serial.

  • 1
    Or pop off the jumpers on the shield and use a couple of jumper wires to connect the right pins of that header to the RX1 and TX1 pins on the Mega. – Majenko Sep 13 '15 at 19:09
  • Thanks, I think I will do as Majenko has suggested and connect it through to Serial1 with some wires. – Calco Sep 14 '15 at 13:21
0

There is a good example on the Arduino site, but in short, you'd use the Serial1 (or -2 or -3) object the same way you use the Serial object:

Serial1.begin(9600);
if( Serial1.available() ){ ... }

etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.