Arduino Leonardo 与XBee的API模式

2015-11-091.5万
AI 快速预览详细 收起
本文讨论了如何使用 Arduino Leonardo 通过串口连接 XBee S2,并将温度传感器数据通过 XBee 的 API 模式发送至协调器。具体问题表现为 Arduino 上没有反应。文章提供了详细的程序代码和调试步骤,帮助用户解决通信故障。
各位前辈高人,我想用Arduino Leonardo的串口连接XBee S2然后将温度传感器采集来的数据发送通过XBee的API模式发送至另一个作为协调器的XBee模块,然后直接在电脑上显示温度数据。但经过实验Arduino上面没有反应,目前Arduino通过TX0 RX1与XBee相连,程序如下:
#include <XBee.h>
#define LM35 A0
XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };
XBeeAddress64 addr64 =XBeeAddress64(0x0013a200, 0x40abc8f5);
ZBTxRequest zbTx =ZBTxRequest(addr64,payload,sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
int val = 0;
float temp = 0;
void setup()
{
Serial1.begin(9600);
  while (!Serial1)
{
   ;
}
xbee.setSerial(Serial1);
}
void loop()
{
val = analogRead(LM35);
temp = val * 0.48876;
payload[0] = val >> 8&0x03;
payload[1] = val&0xff;
xbee.send(zbTx);
delay(1000);
}
我觉得问题可能出在程序未能真正调用Arduino的串口,所以数据根本没有传给Xbee。但我不知道该怎么修改,请各位前辈高人看看,怎么样才能实现正常的通信。

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(2)
Ryan_Wen
Ryan_Wen
作者
没有人知道怎么弄吗?弄不出来很急啊。
dsweiliang
dsweiliang
帮顶
- 没有更多了 -