Help with xbees / arduino serial communication


#1

I’m trying to get two xbees (+2 shields) and two arduinos communicating.

Super basic Serial.print from one xbee1 to xbee2 (just to turn on xbee2’s LED when button on xbee1 is pushed).
The two xbees are communicating when the sender is plugged in and monitored through XCTU (and the receiver is plugged into an arduino) but when receiver is plugged in rx/tx to the arduino, they cease communicating.

Has this happened to anyone else?


// sender code

int buttonPin = 12;
int ledPin = 8;
int buttonState = 0;

void setup (){
  pinMode (buttonPin, INPUT);
  pinMode (ledPin, OUTPUT);

  Serial.begin (9600);
}


void loop(){
    buttonState = digitalRead(buttonPin);
      if (buttonState == HIGH){
      digitalWrite(ledPin, HIGH);
      Serial.print('y');
  }  else {
    digitalWrite(ledPin, LOW);
    Serial.print('x');
  }
}


// receiver code


void setup() {
  Serial.begin(9600);
  pinMode(7,OUTPUT);

  
}
void loop() {
  if(Serial.available()) {
    char getData = Serial.read();
    if(getData == 'x')
    {
      digitalWrite(7,HIGH);
    }
  }
}

#2

It sounds like you’ve confirmed that the two devices are linking and communicating. So, the next things to check are:

a proper ground connection between devices. tx and rx voltage signals are only meaningful relative to a shared ground reference.

be sure transmit (tx) from one device goes to receive (rx) on another device. Simple, but I’ve cross-wired this kind of thing so many times.

Ensure that all systems operate at the same voltage. A 3.3v output won’t register as HIGH to all 5v devices.

You can always add an led+resistor connected to ground to the output of any tx to make sure it’s actually sending something. If it blinks, it’s sending. If not, go back and double check your xbee configurations.

Hope that helps,
Jacob