通信的Arduino其他的Arduino使用RF24得到错误的结果
问题描述:
我使用这些代码转移你好世界,但我只是收到 “& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &“,在接收机 。 我不明白是什么问题。通信的Arduino其他的Arduino使用RF24得到错误的结果
*******************变送器代码:
#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);
}
}
答
您使用的发送站点:
为const char文本[] = “Hello World” 的; radio.write(& text,sizeof(text));
在接收方网站上: char text [32] = {0}; radio.read(& text,sizeof(text));
这两个sizeof(文本)是否等于?
在发送部分文本是11字节 在接收部分文本是32字节