发送端代码:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(5, 6); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(5);
}
接收端代码:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(10, 9); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
Serial.println("connect sucesses!");
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}else{
Serial.println("connect failure!");
}
delay(5);
}
遇到的问题1是通信时显示连接成功但全是乱码,问题二是当我断开发送端的电源时,串口显示也是这样,并不会出现connect failure,很迷茫,希望大佬解答
|