Problems with nrf24l01

Hello everyone,
I am a beginner with the Arduino. I tried to create a communication between two Arduino Nanos.
I connected my antennas to the two arduinos using the following pins.

VCC >> 3.3V
GND >> GND
CE >> D7
CSN >> D8
SCK >> D13
M0 >> D11
M1 >> D12

Problem:
I don't know if I did anything wrong in the code, but when I run it the transceiver tells me that "connection to receiver is available" and "message was not sent".
I hope you can help me. Thanks

transceiver:

RF24 radio(7,8);
const byte address[6] = "00001";

void setup(){
    Serial.begin(9600);
    radio.begin();
    radio.openWritingPipe(address);
    radio.stopListening();
}

void loop(){
    if (radio.available()) {
        Serial.println("Connecting to receiver is available");
    }
    const char text[] = "Hello World";
    if (radio.write(&text, sizeof(text))) {
        Serial.println("Message was sent: ");
        Serial.print(text);
    } else {
        Serial.println("Message was not sent");
    }
    delay(2000);
}

receiver:

RF24 radio(7,8);
const byte address[6] = "00001";

void setup(){
    Serial.begin(9600);
    radio.begin();
    radio.openReadingPipe(0, address);
    radio.startListening();
}

void loop(){
    if (radio.available()) {
        Serial.println("Connection to transceiver is available");
        char receivedText[32] = "";
        radio.read(&receivedText, sizeof(receivedText));
        Serial.println("Message was received: ");
        Serial.print(receivedText);
    } else {
        Serial.println("Connection to transceiver is not available");
    }
}

I hope I have given you all the important information.

Can you try the simple code example in this tutorial ?

Robin2's simple rf24 tutorial helped me to get my radios to work. I had less luck with other tutorials.

The tutorial covers the problems with supplying enough current to the modules. Failure to supply sufficient current is one of the most often problems. I use homemade versions of this adapter on my radios and have no problems with power,

If you are using the higher powered radios (external antennae) they may not communicate if they are too close together. Move them a few meters apart.

The radios do not reset with the Arduino when uploading code. Cycle power to the radios to reset them. after uploading new code to the Arduino.

Thank you both for your quick replies.
I looked at the Robin2 tutorial and tried the code for the one-way transmission and the two-way transmission. In both cases my message was not sent.

I also tried to separate the antennas further. Was a little over a meter.

Do you have any more ideas what I can do?

Here is the package I bought.

Is this maybe because I do not reset correctly? How do I do reset correctly?

Thanks :slight_smile:

This is wrong if you are using the adapter which is shown in the product page for the kit.

Edit:

Also, did you notice that the pin wiring is different if you use the Robin2 tutorial. Look at pins CE and CSN.

Further, that kit appears to come with its own library. Which nrf24L01 library have you installed?

Did you try the CheckConnection.ino from that tutorial ?

Hi, @martenfree
Can you please post a picture of your project so we can see your layout?

Can you please post a circuit diagram of your project?
How are you powering the Nano's and the NRF units?

It looks like you have the HRF with the power amp, so itt will need more current than the smaller regular NRFs.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

You are right and I am stupid. I should have seen that. I have now connected the 5V.
I already swapped the pins for CE and CSN when I saw Robin's tutorial.

I achieved partial success. Now my message is sometimes transmitted. The message is now transmitted very irregularly. Normally it should arrive every 2 seconds, but sometimes it takes 10 seconds or less or more.

Thank you in advance for your answers. You helped me a lot. I've tried so much and it was just because of the great tension. It's very depressing.

Do you have an idea how I can make the transmission constant every 2 seconds?

Thank you all for your help.

transceiver:

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

RF24 radio(9,10);
const byte address[6] = "00001";

void setup(){
    radio.begin();
    radio.openWritingPipe(address);
    radio.stopListening();
}

void loop(){
    const char text[] = "Hello World";
    radio.write(&text, sizeof(text))
    delay(2000);
}

receiver:

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

RF24 radio(9,10);
const byte address[6] = "00001";

void setup(){
    Serial.begin(9600);
    radio.begin();
    radio.openReadingPipe(0, address);
    radio.startListening();
}

void loop(){
    if (radio.available()) {
        char receivedText[32] = "";
        radio.read(&receivedText, sizeof(receivedText));
        Serial.print("Message was received: ");
        Serial.println(receivedText);
    } 
}

Are the examples in Robins tutorial behaving the same way ?

This is likely to be because you are transmitting exactly the same message and it may be wrongly recognised as a re-transmission and, therefore, dropped. I believe some clone NRF24L01 devices behave strangely under these circumstances.

Try this for the transmitter:

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

RF24 radio(9,10);
const byte address[6] = "00001";

void setup(){
    radio.begin();
    radio.openWritingPipe(address);
    radio.stopListening();
}

void loop(){
	static uint8_t i = 0 ;
    const char text[13] = "Hello World";
	text[12] = i++ ;
    radio.write(&text, sizeof(text))
    delay(2000);
}

Try to run the modules with minimal power (RF24_PA_MIN), at least for the tests.

setPALevel() allows you to control that and also the LNA.

https://nrf24.github.io/RF24/classRF24.html#ab6a711a9cc14fb459a4a1698b8665d82

You could care for the outcome of the transmission and repeat it, if it fails?

Hello guys,
I tried a little more. The problem seems to have been that the antennas were still too close to each other. So I put them even further apart.
Now everything works fine.
I would like to thank everyone again, I couldn't go into all of the answers. Thanks