The sender's serial monitor keeps saying transmission failure, but the receiver's serial monitor is receiving the value normally. As the distance between the sender and the receiver increases, it happens more often, so why is that? What is the solution?
Below is the code I used.
//TX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 53
RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
}
void loop() {
static int counter = 0;
bool success = radio.write(&counter, sizeof(counter));
if (success) {
Serial.print("Send Success: ");
Serial.println(counter);
} else {
Serial.println("Send Fail");
if (!radio.isChipConnected()) {
Serial.println("Radio Chip not connected!");
}
}
counter++;
delay(1000);
}
//RX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001";
int receivedData = 0;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
}
void loop() {
if (radio.available()) {
radio.read(&receivedData, sizeof(receivedData));
Serial.println(receivedData);
}
}