Problem about using Raspberry Pi3 and Xbee API mode transfer

Hi All! I’m trying to transfer the DHT22’s data through the xbee and Raspberry Pi3. Im using 2 Xbee and 2 Pi3 to do this.And the xbee are set to coordinator API and router API mode with the same PAIN ID.It shows nothing when i plug the coordinator to computer and check the XCTU. How should i fix this problem?

Here’s the code of coordinator:

import serial                       
ser =serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1.0) 

while 1:            
     a = x [15:-1]               
     if a !='':                   
        print a                     

And this is the wiring with coordinator and first Pi3.

Code for router api:

import Adafruit_DHT as dht
import serial
h,t = dht.read_retry(dht.DHT22, 4)           
A = 'Tmp=%.1f*C,Hum=%.1f%%' % (t, h)           
print a                                       
ser=serial.Serial('/dev/ttyAMA0', baudrate=9600)  

The wiring for Router API:

Are you able to get a response form a Node Discovery from the Coordinator? If not, issue a local network reset (ATNR0) on your router.

It work in arduino.I can monitor the data from XCTU with coordinator.So I’m wondering is that problem with pi? Here’s my arduino code.


unsigned long previousMillis = 0;
const long interval = 4000;
// the interval in mS 
XBee xbee = XBee();
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial soft(2,3);// RX, TX
Rx16Response rx16 = Rx16Response();
ZBRxResponse rx = ZBRxResponse();

XBeeAddress64 addr64 = XBeeAddress64(0x0013a200,0x40D8DA8D);

char Buffer[128];
char RecBuffer[200];
void setup() {
  // put your setup code here, to run once:
void print8Bits(byte c){
  uint8_t nibble = (c >> 4);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
    Serial.write(nibble + 0x37);

  nibble = (uint8_t) (c & 0x0F);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
    Serial.write(nibble + 0x37);

void print32Bits(uint32_t dw){
  print16Bits(dw >> 16);
  print16Bits(dw & 0xFFFF);

void print16Bits(uint16_t w){
  print8Bits(w >> 8);
  print8Bits(w & 0x00FF);

void loop() {
  // put your main code here, to run repeatedly:
  if (xbee.getResponse().isAvailable()) {
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
       if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
            Serial.println("got ACK");
        } else {
            // we got it (obviously) but sender didn't get an ACK
            Serial.println("not got ACK");

        Serial.print("Got an rx packet from: ");
        XBeeAddress64 senderLongAddress = rx.getRemoteAddress64();
        Serial.print(" ");
        Serial.println(' ');
        // this is the actual data you sent
        Serial.println("Received Data: ");
        for (int i = 0; i < rx.getDataLength(); i++) {
          Serial.print(' ');
        //Received data as string to serial
        Serial.println(' ');
        Serial.println("In string format");
       for (int i = 0; i < rx.getDataLength(); i++) {
          if (iscntrl(rx.getData()[i]))
            RecBuffer[i] =' ';
        String myString = String((char *)RecBuffer);
          Serial.println("Switching on Motor");
        else if(myString=="MTOFF"){
          Serial.println("Switching off Motor");
    //clear the char array, other wise data remains in the 
    //buffer and creates unwanted results.
    memset(&RecBuffer[0], 0, sizeof(RecBuffer));
    memset(&Buffer[0], 0, sizeof(Buffer));

  //Send a packet every 4 sec.
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    uint8_t payload[20]= "RSLOW";

//  ZBTxRequest zbtx = ZBTxRequest(addr64,(uint8_t *)Buffer,sizeof(Buffer));
    ZBTxRequest zbtx = ZBTxRequest(addr64,payload,sizeof(payload));


The Pi 3 uses this serial port for bluetooth, the older Pi models did not. I had similar issues changing from an original Pi to Pi 3.

You have to modify some settings to free the port to be used by the header pins for Xbee. Refer to the following: