I have a pair of nRF24L01s connected to a pair of Arduino Unos and I'm using the RF24 library from here: RF24 library. When I run the pingpair example sketch, the radios transmit and receive back and forth just fine. So I tried to program my own very simple example but I'm running into a problem where the first message transmits successfully (and is received successfully), however, subsequent messages fail to send. The call to radio.write() returns false.
I'm using the following code on the 'sender':
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setRetries(15, 15);
radio.setPayloadSize(1);
radio.openWritingPipe(pipes[0]);
}
void loop() {
payload[0] = 1;
bool ok = radio.write(payload, 1);
Serial.println("Status: " + (String) ok);
delay(200);
}
And the following on the 'receiver':
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setRetries(15, 15);
radio.setPayloadSize(1);
radio.openReadingPipe(1, pipes[0]);
radio.startListening();
Serial.println("Listening: " );
}
void loop() {
if (radio.available()) {
bool done = false;
while (!done) {
done = radio.read(payload, 1);
Serial.println("Got payload: " + (String) payload[0]);
}
}
}
I'm guessing the problem has to be with my code because the example sketches work, but I can't figure out what the problem is. Again to summarize, when I reset the Arduino, the first call to radio.write()
returns true and the message is transmitted. After that, subsequent calls to radio.write()
return false.
Also note that I did try adding a 10uF capacitor across +3.3V and Ground but it did not help.
Thanks for any help.