1

I am using one XBee S2 configured as coordinator API attached to my laptop and one XBee S2 attached to an Arduino Uno that is configured as a router AT. I want to generate an alarm on LabVIEW as I have used VISA for serial communication.

#include <SoftwareSerial.h>

int buttonState1 = 0;
SoftwareSerial XBee(2,3); // RX, TX
int pin=13;
void setup() {
    XBee.begin(9600);
    Serial.begin(9600);
    pinMode(2,INPUT);

}

void loop() {
    if (Serial.available())
       buttonState1 = digitalRead(2);

    if (buttonState1 == HIGH) {
       // turn LED on:
       Serial.println(1);

    }
   /*else
    {
        Serial.println(2);

    }*/
    else {
       // turn LED off:
       Serial.println(0);
    }

    delay(100);
}

but I am getting no response at all.

What could be the root cause for this and how do I diagnose that?

migrated from electronics.stackexchange.com Jun 3 '15 at 16:42

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • you have never used XBee Serial, whereas you are supposed to read data from it. – goddland_16 Apr 11 '17 at 4:27
0

Pin 2 & 3 are hardware serial pins. You can't/shouldn't attach softwareserial pins to them.

In short, your SoftwareSerial XBee is never used and uses the same pins of the hardware serial.

What are you actually trying to achieve? I have a hard time understanding it. Though. You should first check if your connection is working.

What devices do you have connected to the arduino?

Is it [Arduino] <-> [XBEE] <-> [PC]?

Test your connection using the code below

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

Source

  • kindly guide me more i am attaching pin2 of xbee with dig0 and pin3 of xbee with dig1 still its not working no response – user10449 Jun 4 '15 at 3:18
  • No, on an UNO the hardware serial pins are 0 and 1. 2 and 3 are the interrupt pins and if the OP isn't using external interrupts he's fine to use them as soft serial. – Delta_G Jun 5 '18 at 5:09
0

Are you using XBee shield or directly connecting it to Arduino and are you using point to point communication between the two XBees?

For getting and sending data between two XBees they must be configured in point to point mode. First, test them to ensure that they are getting data through this communication.

If yes, then issue will be on your LabVIEW VI, because your Arduino code seems to be fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.