[SOLVED]nRF24 comunication not working

Hi there,

basically, I have two nRF24 with antennas and I'm trying to make them comunicate.

The transmitter is linked to a solo atmega328p with external 16mherz clock, the receiver is on an arduino UNO board.

This is the code for the Transmitter, on pin 8 I have a LED which blinks every second.

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

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

const byte address[6] = "00001"; //Pipe

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.stopListening();
}

void loop() {
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(1000);
  const char text[] = "nrftest";
  radio.write(&text, sizeof(text));
}

And this is the code for the receiver:

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

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

const int led1 = 5;
const int led2 = 3;
const byte address[6] = "00001";

void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  radio.begin();
  radio.openReadingPipe(1,address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.startListening();
}

void loop() {
  char text[32] = "";
  String transData = "Yolo";
  if (radio.available()) {
    radio.read(&text, sizeof(text));
    transData = String(text);
    if (transData == "nrftest") {
        digitalWrite(led1, HIGH);
        delay(500);
        digitalWrite(led1, LOW);
        delay(500);
      }    
    else{
      digitalWrite(led2, HIGH);
      delay(500);
        digitalWrite(led2, LOW);
        delay(500);
      }
  }
}

Now, here is what happens:

  1. When I power up the receiver, but not the transmitter led2 starts blinking so radio.available() == true, that's the first thing I don't understand;

  2. When I power up the transmitter too led2 stops blinking and nothing happens;

  3. Led1 (Comunication succesfull) does never blink;

Can someone help me to make them comunicate properly and explain me what's happening? Thanks a lot.

This is the schematics, I know It's kinda bad, but I couldn't find any other software, sorry:

In your transmitter you send "nrftest\0" which is 8 bytes and in your receiver you are trying to receive 32 bytes. You must make sure that the receiver does not ask for more bytes than the transitter sends. And please stop using the "String" class :slight_smile:

EDIT: Another tip: You should not use addresses of more than 5 bytes where the first 4 bytes are identical and the last byte is unique to each (reading) pipe. Try to use an address like "const byte address[] = {0x11, 0x22, 0x33, 0x44, 0x55}" or whatever.

Danois90:
In your transmitter you send "nrftest\0" which is 8 bytes and in your receiver you are trying to receive 32 bytes. You must make sure that the receiver does not ask for more bytes than the transitter sends. And please stop using the "String" class :slight_smile:

Nothing, even with the 8 byte doesnt work :,(

Try to change your transmitter's loop to:

void loop() {
  const char text[] = "nrftest";
  if (radio.write(&text, sizeof(text)))
  {
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(1000);
  }
}

This will enable you to see if data is actually send.

hello,
Check your antenna nrf (it should be male ) .
Add a good capacitor between pwr and gnd.

Danois90:
Try to change your transmitter's loop to:

void loop() {

const char text[] = "nrftest";
  if (radio.write(&text, sizeof(text)))
  {
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(1000);
  }
}




This will enable you to see if data is actually send.

The led isn't blinking

youceforo:
hello,
Check your antenna nrf (it should be male ) .
Add a good capacitor between pwr and gnd.

Antenna should be allright, and the two nrf should work properly, I tried them yesterday and they were working, than I changed some wires and stuff, today I was trying to do other tests and they didnt work anymore, I don't even have the old code / schematics, sadly

UPDATE:

I was touching the wires linked to the Breadboard from the VCC and GRD of the modules and suddenly the SUCCESFULL TRASNFER led blinked a couple of times, I suppose it's something like a power problem, maybe the capacitors will help

Transmit will only work if something is listening for the transmission. You should check your receiver, it is probably not working and your schematic is useless (too small for my eyes). If the standalone chip is powered with 3.3v it will not work at 16Mhz. As "youceforo" mentioned, a 10uf capacitor on the RF24 is a good idea to stabilize the power supply.

Danois90:
Transmit will only work if something is listening for the transmission. You should check your receiver, it is probably not working and your schematic is useless (too small for my eyes). If the standalone chip is powered with 3.3v it will not work at 16Mhz. As "youceforo" mentioned, a 10uf capacitor on the RF24 is a good idea to stabilize the power supply.

Standalone is powered by 5v, nrf-s are powered by 3.3v, I will try with the two capacitors as soon as I find them

1 Like

Have a look at this Simple nRF24L01+ Tutorial.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

The Tutorial includes a program to verify that the Arduino is communicating with the nRF24 it is attached to.

Fritzing diagrams are very easy to misunderstand, but it looks like you are trying to power the two nRF24s from the 3.3v pin on the Uno and I doubt if it can supply enough current. Try powering them from a pair of AA alkaline cells (3v) making sure that the battery GND is connected to the Arduino GND for BOTH Arduinos.

...R

1 Like

Solved, capacitors did all the job :slight_smile: Thanks a lot. At the beguinning I had some problems with the connections because I didn't understand proprerly where to put the capacitors, basically you just have to connect one side to the VCC from the power supply to the module and the other to the ground, thanks a lot everyone.

1 Like