Home/Support/Support Forum/Problem about using Raspberry Pi3 and Xbee API mode transfer
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Problem about using Raspberry Pi3 and Xbee API mode transfer

0 votes
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: x=ser.readline() 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) ser.write(a) ser.close()
The wiring for Router API:
asked Feb 9, 2017 in Digi TransPort Cellular by fxsh1301 New to the Community (1 point)
edited Feb 8, 2017 by fxsh1301

Please log in or register to answer this question.

3 Answers

0 votes
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.
answered Feb 9, 2017 by mvut Veteran of the Digi Community (15,410 points)
0 votes
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.
#include <Printers.h> #include <XBee.h> #include <SoftwareSerial.h> 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: soft.begin(9600); Serial.begin(9600); xbee.setSerial(soft); } void print8Bits(byte c){ uint8_t nibble = (c >> 4); if (nibble <= 9) Serial.write(nibble + 0x30); else Serial.write(nibble + 0x37); nibble = (uint8_t) (c & 0x0F); if (nibble <= 9) Serial.write(nibble + 0x30); else 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: xbee.readPacket(); if (xbee.getResponse().isAvailable()) { if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { xbee.getResponse().getZBRxResponse(rx); 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(); print32Bits(senderLongAddress.getMsb()); Serial.print(" "); print32Bits(senderLongAddress.getLsb()); Serial.println(' '); // this is the actual data you sent Serial.println("Received Data: "); for (int i = 0; i < rx.getDataLength(); i++) { print8Bits(rx.getData()[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] =' '; else RecBuffer[i]=rx.getData()[i]; } Serial.println(RecBuffer); String myString = String((char *)RecBuffer); if(myString=="MTON"){ 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; strcpy(Buffer,"RSLOW"); uint8_t payload[20]= "RSLOW"; // ZBTxRequest zbtx = ZBTxRequest(addr64,(uint8_t *)Buffer,sizeof(Buffer)); ZBTxRequest zbtx = ZBTxRequest(addr64,payload,sizeof(payload)); xbee.send(zbtx); } }
answered Feb 10, 2017 by fxsh1301 New to the Community (1 point)
0 votes
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:

answered May 23, 2017 by mbraden New to the Community (1 point)