1

I'm trying to send a character, in this case the letter 'H', via Xbee through a Raspberry Pi with an Xbee USB explorer attached to it and receive the response "Hello" from an Arduino with an Xbee attached to a wireless proto shield.

Code on Raspberry:

from xbee import ZigBee
import serial

ser  = serial.Serial('/dev/ttyUSB0',9600)

xbee = ZigBee(ser)

xbee.send('tx',dest_addr_long=b'\x00\x13\xA2\x00\x41\x49\x69\xD6', 
dest_addr=b'\xFF\xFE',data=b'H')

while True:
    try:
       print(xbee.wait_read_frame())
except KeyboardInterrupt:
       break

ser.close()

Code on Arduino:

#include <SoftwareSerial.h>
// We'll use SoftwareSerial to communicate with the XBee:
SoftwareSerial Xbee(0, 1); // RX, TX

int incomingByte;

void setup() {
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  Xbee.begin(9600);
  Serial.begin(9600);
}

void loop() {
  if (Xbee.available()) {
    // If data comes in from serial monitor, send it out to XBee
    incomingByte = Xbee.read();
    if(incomingByte == 'H') {
      Serial.write("Hello");
    }
  }
}

The issue is when I run the code I only receive the transmit status on the Raspberry Pi, and not the packet with the "Hello" response in it.

Running code on Raspberry Pi:

Running Code on Py

I checked this by running the same scenario using XCTU tool and I do receive a response packet with the "Hello" message in it. So how can I get the Raspberry Pi to detect the response packet?

gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

0

Simple error. You aren't sending anything back to the XBee serial port.

Replace:

Serial.write("Hello");

With:

Xbee.write("Hello");
tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • Didn't fix anything. I know the Xbee on the arduino is communicating with the xbee attached to my pc because I get a response from the arduino on the xctu application it's just not showing up when I run my python script on the raspberry pi. – Claudio Gonzalez Mar 22 '18 at 17:48
  • Are you sure the Arduino is receiving the `H`? Maybe there's a mistake with your hardware connections. Can you connect a logic probe to the XBee serial lines to see data going in/out of the XBee? Can you update your Arduino code to turn on an LED (or echo to the console) when it receives the `H` and tries to send `Hello`? – tomlogic Mar 23 '18 at 17:51
  • Also note that the XBee uses `DH` and `DL` to identify the target for serial data it's going to send. Make sure the XBee on the Arduino has its `DH` and `DL` set to the `SH` and `SL` of the XBee on the RPi. (But you can use `0` in `DH` and `DL` to target the coordinator.) – tomlogic Mar 23 '18 at 18:17
  • I attached an LED to check the Arduino was receiving the signal and I can confirm that it is. As for the DH and DL on the Arduino it is configured to target the coordinator. I tried both methods and non of them changed anything. – Claudio Gonzalez Mar 23 '18 at 19:03