Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
两个arduinos之间api模式下的Xbee通信_Arduino_Arduino Uno_Xbee_Lcd - Fatal编程技术网

两个arduinos之间api模式下的Xbee通信

两个arduinos之间api模式下的Xbee通信,arduino,arduino-uno,xbee,lcd,Arduino,Arduino Uno,Xbee,Lcd,我有两个Arduino Unos,两个LCD和Xbee s2。 我将两个xbee s2模块连接到每个arduino uno。 我努力搜索这个实现并尝试了它。 但是,它不起作用。我感谢你的帮助 配置:AP=2 协调器API和路由器API 发送者:路由器 #include <XBee.h> #include <SoftwareSerial.h #include <LiquidCrystal.h> #define LED 13 LiquidCrystal

我有两个Arduino Unos,两个LCD和Xbee s2。 我将两个xbee s2模块连接到每个arduino uno。 我努力搜索这个实现并尝试了它。 但是,它不起作用。我感谢你的帮助

配置:AP=2 协调器API和路由器API

发送者:路由器

 #include <XBee.h>
       #include <SoftwareSerial.h

#include <LiquidCrystal.h>
#define LED 13
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial xSerial(3,4);
XBee xbee=XBee();
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

void setup(){
  //Serial.begin(9600);
  xSerial.begin(9600);
  xbee.setSerial(xSerial);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, Gang!");
  //Serial.println("xbee start");
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  delay(3000);
}

void loop(){
  ZBTxRequest zbTx;
  uint8_t payload[]={'H', 'E', 'Y', '\0'};
  XBeeAddress64 address=XBeeAddress64(0x13a200, 0x40b450f4);
  zbTx=ZBTxRequest(address, payload, sizeof(payload));
  xbee.send(zbTx);
   if (xbee.readPacket(500)) {              
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        lcd.setCursor(0,1);
        lcd.print("Success");
      } else {
        // the remote XBee did not receive our packet. is it powered on?
      }
    }
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
  }

  delay(1000);
}
#包括

#include我已经用Arduino完成了两个XBee之间的通信,您可以查看我的编码并尝试稍微更改一下您的编码

寄件人=

#包括
#定义Dout 2
#定义Din 3
#定义LED 9
软件串行XBeeSerial(Dout,Din);
无效设置(){
XBeeSerial.begin(9600);
引脚模式(LED,输出);
}
void循环(){
延迟(500);
XBeeSerial.write(“+”);
模拟写入(LED,13);
延迟(3000);
XBeeSerial.write(“-”);
模拟写入(LED,0);
延迟(500);
}
您是否确认(可能是X-CTU)XBee无线电已形成网络?你有没有从XBee收到任何画面?您的XBee库是否配置为使用ATAP=2而不是ATAP=1?你有正确的波特率吗?如果您将接收XBee连接到运行X-CTU的计算机,它是否显示接收到的帧?你确认了什么是有效的,你是否已经隔离了问题?
#include <SoftwareSerial.h>
#include <XBee.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

SoftwareSerial xSerial(3,4);

XBee xbee=XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();

void setup(){
  xSerial.begin(9600);
  xbee.setSerial(xSerial);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, tang!");
  delay(3000);  
}

void loop(){
  xbee.readPacket();
  if (xbee.getResponse().isAvailable()) {
      // got something
      lcd.setCursor(0, 1);
      lcd.print( "MSG");
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);
        lcd.setCursor(0, 1);
        lcd.print(rx.getData(1));

        if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
            lcd.setCursor(0,1);
            lcd.print( "ACK");

        } else {
            lcd.setCursor(0,1);
            lcd.print("ERROR");
        }
      } else {
        // not something we were expecting
        //flashLed(errorLed, 1, 25);   
       lcd.print("7 print"); 
      }
    } else if (xbee.getResponse().isError()) {
      lcd.print("error");
    }
    delay(3000);
}