I have a Xbee shield on a UNO.
The XBee is receiving data in transparent mode and sending it to the UNO which in turn displays it on a LCD . All working fine powered by the USB port on the UNO.
Now i open the Arduino IDE and choose the port of the UNO and I can see the data in the Serial Monitor also !! How is this possible ? Is it that in this mode the Serial Monitor sniffs the data passing through the XBee and UNO ?
The relevant code is below :
#include <LedFlasher.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LedFlasher heartBeat (13, 250, 250);
// Define the LCD pins to use and Initialize an instance
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7); // [C] I2C bus address of LCD module..mostly 0x27.
// List all global variables....
char lcdString[17];
bool started = false; //True: Message is strated
bool ended = false; //True: Message is finished
char incomingByte ; //Variable to store the incoming byte
char dataFromXbee[16]; //Message
byte index; //Index of array
void setup() {
Serial.begin(9600);
heartBeat.begin();
Serial.println( " Started the XBee Rx !!" );
// START THE I2C INTERFACE
Wire.begin();
// START THE LCD INTERFACE
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.clear();
lcd.write( " XBEE Tx CODE " );
lcd.setCursor(0, 1);
lcd.write( " Version : 1.00 " );
delay (2000);
lcd.clear();
}
void loop() {
heartBeat.update();
while (Serial.available() > 0) { //Read the incoming byte
incomingByte = Serial.read();
if (incomingByte == '<') //Start the message when the '<' symbol is received
{
started = true;
index = 0;
dataFromXbee[index] = '\0'; // Throw away any incomplete characters
}
else if (incomingByte == '>') //End the message when the '>' symbol is received
{
ended = true;
break; // Done reading - exit from while loop!
}
else //Read the message!
{
if (index < 16) // Make sure there is room
{
dataFromXbee[index] = incomingByte; // Add char to array
index++;
dataFromXbee[index] = '\0'; // Add NULL to end.. keep on adding..overwriting
}
}
}
if (started && ended)
{
sprintf(lcdString , "%s", dataFromXbee);
lcd.setCursor(0,0);
lcd.print(lcdString);
Serial.println(lcdString);
index = 0;
dataFromXbee[index] = '\0';
started = false;
ended = false;
}
}