【发布时间】:2015-04-26 19:01:43
【问题描述】:
我有两个 Arduino Unos、两个液晶显示器和 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 <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);
}
啊,我将 xbee s2 连接到 arduino 上的 xbee pro shield。 xbee shield 上没有 dline/uart 开关。所以,我使用软件序列库...但它没有工作。
【问题讨论】:
-
您是否确认(可能与 X-CTU 一起)XBee 无线电已形成网络?您是否从 XBee 获得任何帧?您的 XBee 库是否配置为使用 ATAP=2 而不是 ATAP=1?你有正确的波特率吗?如果将接收 XBee 连接到运行 X-CTU 的计算机,它会显示接收到的帧吗?您确认什么是有效的并且您是否完全隔离了问题?
标签: arduino arduino-uno xbee lcd