【问题标题】:Arduino Mega won't read serial from XBee coordinator in API modeArduino Mega 不会在 API 模式下从 XBee 协调器读取串行
【发布时间】:2016-09-30 19:26:11
【问题描述】:

我有两个XBees

  • 一个是路由器 AT 从一个模拟设备读取和发送模拟数据 别针。
  • 另一个是连接到 Arduino Mega 的协调器 API 串行端口(rx1 和 tx1)。

每当我尝试从 Arduino 中的 XBee 串行读取时,读数大多为零(而不是应有的数据包)。

必须注意,使用 xctu 终端或任何其他终端,我可以毫无问题地读取正确的数据。

这是我正在使用的一些示例代码:

void setup() {
    Serial1.begin(9600); // Here the XBee is connected
    Serial.begin(9600);
}

void loop() {
    if (Serial1.available()){
        Serial.print(Serial1.read());
    }

【问题讨论】:

  • 您必须检查 Xbee 和 Arduino 之间的连接。它必须是 [Tx(arduino) Rx(Xbee)] & [Rx(arduino) Tx(Xbee)]。
  • loop() 中没有“}”吗?或者 loop() 是否包含比显示更多的代码?还是if 子句中的更多代码?

标签: arduino xbee


【解决方案1】:

几个小时后,我终于能够修复它。我不知道具体原因,但似乎将 tx1 和 rx1 以相反的顺序连接已经解决了问题,现在我可以在我的 XBees 之间进行通信了。

【讨论】:

  • 您通常将一台设备的 TX(发送)连接到另一台设备的 RX(接收)。这就是你现在的工作方式吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多