Go Down

Topic: nRF24L01 with RF24 library can send one message and then goes silent (Read 151 times) previous topic - next topic

pirkk

Code: [Select]
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include "printf.h"

RF24 radio(7, 8);
const uint64_t pipe = 0xDADBADLL;

void setup() {
 
  // put your setup code here, to run once:
  Serial.begin(57600);
  printf_begin();
 
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(pipe);
  radio.stopListening();
  radio.printDetails();
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()) {
    char data[120];
    int i;
    for(i = 0; Serial.available(); i++) {
      data[i] = Serial.read();
    }
    data[i] = '\0';
    Serial.println(data);
    radio.write(&data, strlen(data));
  }
  delay(100);
}


So that's my nRF24L01 transmitter code. What it does is it sends a message from the Serial to the receiving antenna. That all works fine, but only once, and if I try to send a message after that nothing happens. Restarting the transmitter resets it and I can send another 1 message again. Restarting the receiver does nothing. What am I missing that's preventing me from sending another? Sorry I am very new to wireless.

Robin2

Have a look at this Simple nRF24L01+ Tutorial. Note that I use the newer TMRh20 version of the RF24 library which solves some problems from the earlier ManiacBug version.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up