Serial Monitor - A basic doubt !

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;
  }

}

It doesn’t seem to need to sniff very deeply. You have the signals on the serial port ,i.e. hardware serial, which is shared with the serial monitor on the USB port. I assume you uploaded the programme with the XBee disconnected, and therefore did not have a problem.

Nick_Pyner:
It doesn't seem to need to sniff very deeply. You have the signals on the serial port ,i.e. hardware serial, which is shared with the serial monitor on the USB port. I assume you uploaded the programme with the XBee disconnected, and therefore did not have a problem.

Yes when i uploaded the code to UNO i disconnected the XBee. So no issues.

The point i am not clear about it is this : When two objects ( Uno and Xbee ) are in communication with each other using Serial protocol, how is a third object - namely by laptop - able to access the same data ?

Serial is supposed to be a Point-to-Point protocol ...right ??

Ardubit:
Serial is supposed to be a Point-to-Point protocol ...right ??

The Serial Monitor is just eavesdropping on the conversation between the Arduino and the XBee.

You can connect several listeners to a single Serial TX line. However adding several "talkers" to a single RX line requires some additional components.

...R

Robin2:
The Serial Monitor is just eavesdropping on the conversation between the Arduino and the XBee.

You can connect several listeners to a single Serial TX line. However adding several "talkers" to a single RX line requires some additional components.

...R

Oh that makes it clear ... eavesdropping !! Never realized that this was possible ( one to many and many to one )on a serial link. Thanks !

If that be the case then who do some terminals complain that the "Port is already open " when you try to connect to such a link up between two items ?

Ardubit:
If that be the case then who do some terminals complain that the "Port is already open " when you try to connect to such a link up between two items ?

That is a different problem entirely. Within the PC it is not possible to share serial ports. And if you are connecting to the PC with a USB cable there is actually no serial data (in the Arduino sense) until the signal gets past the USB-TTL converter on the Arduino board (assuming you are using and Uno, Nano or Mega. Prior to the USB-TTL converter it is USB data.

...R