One to One communication between Arduino and PC

I want to establish communication between Arduino UNO and the PC it is connected with via USB port. In one stage of the sketch, I want the Arduino to request for an input from User. While the user sends something to Arduino, Arduino will work with it and sends a message to another Arduino using Xbee.

Will it be possible using C or C++ or Processing? Would appreciate your suggestion to start off this project.

Will it be possible using C or C++?

Yes.

You could develop all the Arduino code using the Serial Monitor application on the PC in place of the C or C++ application you have yet to develop.

Thanks for your reply.

Tried to implement a simple numerical input in serial monitor. When there is no xbee it’s working ok but presumably when putting xbee, the input I am giving in serial monitor is not showing. As well as nothing is going to the remote Xbee+arduino. So, I have tried with <SoftwareSerial.h> but no luck. I am giving here the code for transmitter and receiver for your input:

For Transmitter [The one that is connected with PC]

#include <SoftwareSerial.h>
SoftwareSerial xbee(10, 11); // RX, TX

  int inputValue=0;     // blink rate stored in this variable
  int value;
  int IDa=10001;

  void setup()
  {
  Serial.begin(9600); // Initialize serial port to send and receive at 9600 baud
  Serial.println("Put your desired number: ");
  xbee.begin (9600);
  }

  void loop()
  {
  if( Serial.available())
  {
    char ch = Serial.read();
    if( isDigit(ch) )// is this an ascii digit between 0 and 9?
    {
       value = (value * 10) + (ch - '0'); // yes, accumulate the value
    }
    else if (ch == 10)  // is the character the newline character?
    {
       inputValue = value;
       //Serial.println(inputValue);
       xbee.println(inputValue);
       value = 0; // reset val to 0 ready for the next sequence of digits    
    }
  }
  handleInputValue();
  delay(2000);
}

  // showing the inputValue in the serial command window
  // passing the inputValue to the receiver
  void handleInputValue()
  {
  //Serial.println(inputValue);
  xbee.println(inputValue);
  
  }

For Receiver [The remote Xbee+Arduino Node]:

#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial xbee(10,11);

  void setup()
  {
   // Open serial communications and wait for port to open:
   Serial.begin(9600);
   // Start each software serial port
   xbee.begin(9600);
  }

  void loop()
  {
    xbee.listen();
    Serial.println("Data from port one:");
    // while there is data coming in, read it
    // and send to the hardware serial port:
    while (xbee.available() > 0) {
    char inByte = xbee.read();
    Serial.write(inByte);
  }
}

I don’t understand where is the problem in this code.

    xbee.listen();

When there is only one instance of the SoftwareSerial class, there is no ambiguity as to which is listening. This is not needed.

How are the XBees attached to the Arduinos?

Thanks again for your reply.

I am using Xbee Series 1. The Xbees are with default configuration (i.e. default PAN ID) and nothing has been changed. I changed it before and put it in unicast mode (in AT) for them but the result is same. I am using this https://solarbotics.com/product/51835/ as interface between Xbee and Arduino.

I am using Xbee Series 1. The Xbees are with default configuration (i.e. default PAN ID) and nothing has been changed

digi's nonsense strikes again. They claim, completely erroneously, that two XBees will communicate out of the box with no configuration changes needed. Complete nonsense.

Two XBees talk to each other if the MY address on one is the DL address of the other one. Configure one of your XBees with MY=1001 and DL=1002. Configure the other one with MY=1002 and DL=1001. Then, they will be able to talk to each other. You can use any pair of values you like, as long as the pairs do not involve 0x0000 or 0xFFFF.

Though I already tried it this way but again put the MY and DL and experimented. Unfortunately that didn’t improve the result.

To understand what is going on, I tried to connect the two arduino with wires. I put RX TX to TX RX [I put two wires in 4 and 5 port of both arduino configured as SoftwareSerial xbee (4,5)] and run the same sketch and saw they are working. But as soon as the xbee+xbee shield is placed it stopped working. What I feel is the receiver is not working, as I tried to send a simple Hello World message and that is also not showing [when configured with SoftwareSerial] when xbee is placed. I don’t understand whether there is anything I have to change in Xbee Shield.

Update: The shield I am using is a discontinued producthttps://solarbotics.com/product/51835/. Does it have something to do with the problem I am encountering? is this a clue: http://stackoverflow.com/questions/17181756/how-arduino-xbee-avoids-using-the-serial-i-o-port

Does it have something to do with the problem I am encountering?

No. The reason that shield is discontinued is that it doesn't play well with other shields, and that it uses jumpers to determine what gets connected to what.

You'll need to stop tap dancing around the configuration issue, and tell us what PAN ID, MY, and DL are on the one XBee and what PAN ID, MY, and DL are on the other XBee. You'll also need to tell us where you have placed the jumpers on each shield.

Using XBees is really quite simple.

tell us what PAN ID, MY, and DL are on the one XBee and what PAN ID, MY, and DL are on the other XBee. You'll also need to tell us where you have placed the jumpers on each shield.

Transmitter: PAN ID: 3332 DL: 1002 MY: 1001

Receiver: PAN ID: 3332 DL: 1001 MY: 1002

The jumper is placed on Xbee side of the Xbee/USB pins for both of the Xbee shields.

The jumper is placed on Xbee side of the Xbee/USB pins for both of the Xbee shields.

I have two of those shields, but I haven't use them for ages. I can only find one of them now. When your Arduinos are powered, does the Associate light on each shield light up properly?

The configuration looks correct.

What I feel is the receiver is not working, as I tried to send a simple Hello World message and that is also not showing [when configured with SoftwareSerial] when xbee is placed. I don't understand whether there is anything I have to change in Xbee Shield.

That shield ONLY allows you to connect (jumper in XBee position) or not connect (jumper in USB position) the XBee to the hardware serial pins. It does not allow you to connect the XBee to other pins (for SoftwareSerial to read/write).

I have two of those shields, but I haven’t use them for ages. I can only find one of them now. When your Arduinos are powered, does the Associate light on each shield light up properly?

Just my luck!
Yah the Xbee shield lights are up while I connect them and blinking the whole time.

PaulS, in one post you probably said that this shield can not work with SoftwareSerial library. Would you let me know whether this is what you meant or you meant something else and I misunderstood?

Would you let me know whether this is what you meant

That is what I said. The jumpers allow connecting the XBee to the hardware serial pins OR the not. When the XBee is connected to the hardware serial pins, sketches can not be uploaded.

That shield does not offer an option to connect the XBee to other pins, that could be read from/written to by SoftwareSerial.

That shield does not offer an option to connect the XBee to other pins, that could be read from/written to by SoftwareSerial.

Sad to know that. May you please suggest me whether this shield [https://www.sparkfun.com/products/10854] may work for SoftwareSerial.h?

Regarding the project I am trying to do: As I need an input from user atleast once during the process while two xbee nodes (xbee+Arduinos) are communicating with each other, I don’t think there is any other way to do this without using <SoftwareSerial.h>, is there any?

May you please suggest me whether this shield [https://www.sparkfun.com/products/10854] may work for SoftwareSerial.h?

The site says:

The serial pins (DIN and DOUT) of the XBee are connected through an SPDT switch, which allows you to select a connection to either the UART pins (D0, D1) or any digital pins on the Arduino (D2 and D3 default).

So, yes, put the switch in one position to use the hardware serial pins and the other position to use the software serial pins.

The “D2 and D3 by default” part is rubbish. There is no possibility to use other pins. The site should just say “or two other digital pins on the Arduino (D2 and D3)”.

I don’t think there is any other way to do this without using <SoftwareSerial.h>, is there any?

There is, but having the XBees communicate with the Arduinos via SoftwareSerial rather than HardwareSerial will be far simpler.

Otherwise, you’ll have trouble differentiating between what the Arduino gets from the XBee and what it gets from the PC. There’s a clue in there, though, if you insist on going that route.