2

I am using the NRF module for remote communucation.I have been many research about nrf but my nrf module is not working This is my tranmistter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8,4000000); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setRetries(15,15);
  radio.setPALevel(RF24_PA_HIGH);
 
}

void loop() {
  radio.stopListening();
  const char text[32]="Hello world";
  if(radio.write(&text,sizeof(text))){
    Serial.println("Mesaj gönderildi");
  }
  delay(1000);

This is my receiver code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8,4000000); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  radio.begin();
  delay(400);
  radio.openReadingPipe(1, address);
  radio.setPALevel(RF24_PA_MAX);
//  radio.startListening();
   pinMode(10,OUTPUT);

}

void loop() {
 const char text[32]="";
  radio.startListening();
  if(radio.available())
  {
    while(radio.available()){
    radio.read(&text[0],sizeof(text[0]));
    Serial.println(text);
    delay(1000);
    }
  }
  delay(5);
   
  
  
}

ı tried the setPAlevel min but there is no change.In the transmitter side the write function returns true, but I can't get anything on the receiver side. Also, if I replace the cable connected to miso with the cable connected to mosi on the transmistter side, the write function still returns true. I also used adaptor ams1117

6
  • 1
    From your Receiver code: radio.read(&text[0],sizeof(text[0])); This looks odd. sizeof(text[0]) is only one byte.
    – 6v6gt
    Commented Jun 17, 2023 at 16:48
  • I tried this buy now ı am trying gettinstarted examples in arduino.Mosi and miso pins does not connect to microcontroller but output which ı take is this:Tranmission successful.
    – koraysonal
    Commented Jun 17, 2023 at 20:16
  • Also.I get a radio hardware not responding error when mosi is connected to the arduino mosi pin on the adapter and miso on the adapter is connected to the miso pin on the arduino.When I reverse the cables and connect them, the transmission and reception occur.
    – koraysonal
    Commented Jun 17, 2023 at 20:41
  • const char text[32]=""; from the receiver also looks odd because this buffer is supposed to be writable. Anyway, use the code from the thread here: forum.arduino.cc/t/simple-nrf24l01-2-4ghz-transceiver-demo/… to test your nrf24L01 devices. Most problems with these nrf24L01 devices are related to inadequate power supplies.
    – 6v6gt
    Commented Jun 18, 2023 at 5:14
  • "When I reverse the cables and connect them, the transmission and reception occur." Does this mean that if you cross over MISO and MOSI on the nrf24L01 adapter board, it all works as expected? I'd be surprised considering the other errors but I suppose it could be a labeling error somewhere.
    – 6v6gt
    Commented Jun 18, 2023 at 5:38

1 Answer 1

1

In the receiver code, you are just reading one byte, as 6v6gt pointed out. Check the library to see how read() works.

If you follow the getting started example, this is how you should read bytes in the receiver:

char text[32];

if (radio.available()) 
{
  uint8_t bytes = radio.getPayloadSize();  // get the size of the payload
  radio.read(&text, bytes);                // fetch payload from FIFO
}

Don't use const for text in the receiver. Also, you don't need to use stopListening and startListening in the loop(). They should just go to setup().

2
  • 1
    Tranmission failed or timed out erros is occured.I tried many things but this error is still continues
    – koraysonal
    Commented Jun 18, 2023 at 17:18
  • Update the code in the question that you tried last.
    – Fahad
    Commented Jun 22, 2023 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.