【问题标题】:communicating arduino to the other Arduino using RF24 getting the wrong result使用 RF24 将 arduino 与另一个 Arduino 通信得到错误的结果
【发布时间】:2016-05-17 05:22:31
【问题描述】:

我使用这些代码来传输你好世界,但我只是收到 "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 在接收器中。 我不明白这是什么问题。

************************发射器代码:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);

  radio.stopListening();
}

void loop()
{
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));

  delay(1000);
}

**********************接收方代码:

    #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  while (!Serial);
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(0, rxAddr);

  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));

    Serial.println(text);
  }
}

【问题讨论】:

    标签: arduino communication wireless


    【解决方案1】:

    在您使用的发送网站上:

    const char text[] = "Hello World"; radio.write(&text, sizeof(text));

    在接收方网站上: 字符文本[32] = {0}; radio.read(&text, sizeof(text));

    sizeof(text) 是否相等?

    在发送部分文本是 11 个字节 在接收部分文本是32字节

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 2015-08-19
      相关资源
      最近更新 更多