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:
#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
}
}