Pages: [1]   Go Down
Author Topic: XBee and EMIC not playing together  (Read 362 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to use the XBee and EMIC2 chip together in the same project.

The XBee code that I'm using works (it is a simple loopback test) Master XBee send char or series of chars to Receiver XBee - who is in loopback mode and sends the chars back to the Master. Once the Master has the chars it prints them to the serial monitor. Alls good until - I include the EMIC2 emicSerial.begin(9600) in the Setup. Soon as I include this line the receiver doesn't send any data back. Or the XBee isn't sending I don't know that either.

Any ideas? I'm not getting any errors. I'm guessing there's some conflict with the additional emicSerial port.

If I comment out the emicSerial.begin(9600); in the Seutp I get Outgoing and Incoming data. When I uncomment the emicSerial.begin(9600); I do not get Incoming data.

Here's what I have:

Code:
#include <SoftwareSerial.h>

#define Rx    6     // DOUT to pin 6
#define Tx    7     // DIN to pin 7
SoftwareSerial Xbee = SoftwareSerial(Rx, Tx);

#define rxPin 2    // Serial input (connects to Emic 2 SOUT)
#define txPin 3    // Serial output (connects to Emic 2 SIN)
#define ledPin 13

SoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);

void setup() {
  // Set to No line ending;
  Serial.begin(9600);
  Xbee.begin(9600);
  delay(500);

  emicSerial.begin(9600);
  /*
    When the Emic 2 powers on, it takes about 3 seconds for it to successfully
    intialize. It then sends a ":" character to indicate it's ready to accept
    commands. If the Emic 2 is already initialized, a CR will also cause it
    to send a ":"
  */

/*  emicSerial.print('\n');             // Send a CR in case the system is already up
  while (emicSerial.read() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
  delay(10);                          // Short delay
  emicSerial.flush();                 // Flush the receive buffer 
*/  Serial.println("Setup Done"); // so I can keep track of what is loaded
}

void loop() {
  while(Serial.available()) {          // Is serial data available?
    char outgoing = Serial.read();  // Read character, send to XBee
    Xbee.print(outgoing);
    Serial.print("Outgoing: ");
    Serial.println(outgoing);
  }
 
    while(Xbee.available()) {            // Is data available from XBee?
    char incoming = Xbee.read();    // Read character,
   
    Serial.print("Incoming: ");
    Serial.println(incoming);       //   send to Serial Monitor   
   
    }
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49082
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only have one instance of SoftwareSerial listening at a time. The one that is listening in your code is emicSerial, because that is the last one created. So, the XBee is being ignored.

You can call Xbee.listen() when you want the XBee to listen to the software serial port.
Logged

Pages: [1]   Go Up
Jump to: