Serial Communication Between PC and Arduino and Arduino to XBee

Good afternoon guys!

I’ve run towards a problem in which I have still no apparent and probable approach. But for now, I have some assumptions but I’m afraid I might mess up with the hardware. I have no one to ask among my friends or our seniors regarding this, even our adviser for the project. No one is still familiar with the XBee hardware and its workings. Plus some hardware I’m going to mention, although I’m very willing to learn.

So here’s my dilemma:

  1. I’m following Matthijs Koojiman’s book, Building Wireless Sensor Networks using Arduino. I’ve been kind of stuck with the “Receiving Data” part, wherein I’m still kind of clueless as to why should I connect pins 2/3 to 8/9 of the XBee shield. The pic is shown in the attached pic, XbeeShield.jpg

  2. The example requires me to communicate with the computer using the Arduino Serial Monitor at 115200 baud, wherein the Arduino has to communicate with the XBee Module mounted to the XBee Explorer board at 9600 baud (the tutorial uses an XBee Shield from Sparkfun).

  3. My hardware setup is shown at XBeeArduinoPC.jpg. The Tx of the Arduino is pin 1 and Rx of the Arduino is pin 0 (just in case someone would ask).

  4. I configured the 2 XBees, 1 Router and 1 Coordinator. I made both their DHs and DLs as 0x0000 and 0xFFFF. PAN ID and Channels are the same. I made this in accordance to the tutorial. In AT and API mode, the two devices can communicate with each other in console or Transmit Request frame. I used “Hello, world!” as my packet data.

  5. The code in the Arduino is shown here and uses the AltSoftSerial library by Paul Stoffregen.

// This example reads data from an AltSoftSerial port and prints this
// (in both hexadecimal and ASCII) to the main serial port (to be read
// on a computer). Any data received from the computer is forwarded to
// the AltSoftSerial port as-is. This is intended to dump all data
// received from an XBee module and allow sending data back to it, but
// can of course be used in other situations too.
// Typical output looks like this:
// Starting…
// 7E 00 19 90 00 13 A2 00 ~…
// 40 D8 5F 9D 00 00 02 48 @._…H
// 65 6C 6C 6F 2C 20 57 6F ello, Wo
// 72 6C 64 21 3B rld!;

#include <AltSoftSerial.h>

// Use some macros to allow changing the serial ports to use easily
AltSoftSerial SoftSerial;
#define DebugSerial Serial
#define XBeeSerial SoftSerial

void setup() {

void loop() {
if (XBeeSerial.available()) {
char data[8];
uint8_t column;
for (column = 0; column < sizeof(data); ++column) {
// Wait up to 1 second for more data before writing out the line
uint32_t start = millis();
while (!XBeeSerial.available() && (millis() - start) < 1000) /* nothing */;
if (!XBeeSerial.available())

// Start of API packet, break to a new line
// In transparent mode, this causes every ~ to start a newline,
// but that’s ok.
if (column && XBeeSerial.peek() == 0x7E)

// Read one byte and print it in hexadecimal. Store its value in
// data, or store ‘.’ is the byte is not printable. data will
// be printed later as an “ASCII” version of the data.
uint8_t b =;
data[column] = isprint(b) ? b : ‘.’;
if (b < 0x10) DebugSerial.write(‘0’);
DebugSerial.print(b, HEX);
DebugSerial.write(’ ');

// Fill any missing columns with spaces to align lines
for (uint8_t i = column; i < sizeof(data); ++i)
Serial.print(F(" "));

// Finalize the line by adding the raw printable data and a newline.
DebugSerial.write(’ ');
DebugSerial.write(data, column);

// Forward any data from the computer directly to the XBee module
if (DebugSerial.available())

  1. My console should be showing “Hello, world!” but instead only shows “Starting…” which is mentioned in the void.setup portion. Why is this?

I’m going to attach the html file of the site in zip/rar, just in case.

I’m really sorry for the long post, but I just wanted everything else to be mentioned before asked by anyone. Thank you for your time!


Please display your image(s) in your post so we can see it(them) without downloading it(them). See this Simple Image Guide

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum


An XBee shield with no XBee seems rather pointless. You DO have an XBee, don't you? A pair of them, actually.


This one is for my XBee to Arduino to PC configuration.

This one on the other hand, is the XBee shield and wiring configuration as shown in Matthijs' book.

I never thought I could be still somehow so unclear. XD I'm sorry.

Is it that you can't use a serial connection between the XBee and your Arduino (Tx/Rx->Rx/Tx) if you're going to use the serial monitor for the Arduino at the same time? I'm sorry I'm still new to electronics and provides first-hand info for me. :smiley: Thank you

Is it that you can't use a serial connection between the XBee and your Arduino (Tx/Rx->Rx/Tx) if you're going to use the serial monitor for the Arduino at the same time?

You might be able to use the same port. Think of the port as a telephone. You can use the phone to call one friend, or you can use it to make a conference call, and talk to two co-workers at the same time.

Suppose your two co-workers are called PC and XBee. Everything you (the Arduino) says is going to be heard by both of your co-workers, and everything either one says is going to be heard by you.

Co-worker XBee is repeating everything you say, and, presumably, some other XBee is hanging on every word, passing it along to some other device (PC? Arduino?).

Now, some things you say, you want your co-worker PC to do something about, and some things you want your co-worker XBee to do something about.

Could you figure out a way to make it clear to each of your co-workers which things you say they should care about?

I'm sure you could, but, it might be easier to just use two phones, and talk to each one of them one at a time.

Now, if you only have one land line phone (hardware serial port), you need to use something else to talk to the other co-worker - a cell phone (software serial port), perhaps.

Now, just like there are multiple cell phone service providers, with various pricing plans and coverage and impact, there are multiple software serial libraries - SoftwareSerial, AltSoftSerial, NeoSWSerial, etc.

But, I STILL don't see an XBee in any of your pictures, so I don't know which one(s) you have. Nor do I see anything about how you have configured it (them). Nor do I see anything about what the XBee is supposed to be talking to.