Go Down

Topic: I'm having problems sending data with nRF24l01 module (Read 246 times) previous topic - next topic

GabrielYamamoto

Oct 21, 2018, 10:14 pm Last Edit: Oct 21, 2018, 10:15 pm by GabrielYamamoto
The nRF24L01 module only sends data when I put something very close it, but if I don't put nothing close, it don't sends any data.

My trasnmitter code:
Code: [Select]
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 8); //CE, CSN

const byte rxAddr[6] = "00001";

void setup()
{
  SPI.begin();
  radio.begin();
  Serial.begin(9600);
  radio.setRetries(15, 15);
  radio.stopListening();
  radio.openWritingPipe(rxAddr);
  delay(100);
}

void loop()
{
  const char text[] = "Hello World";
  radio.stopListening();
  radio.write(&text, sizeof(text));
  Serial.println("sending");
  delay(1000);
}



My receiver code:
Code: [Select]
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(4, 3);

const byte rxAddr[6] = "00001";

void setup()
{
  SPI.begin();
  while (!Serial);
    Serial.begin(115200);
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  radio.startListening();
  radio.flush_rx();
}

void loop()
{
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
   
    Serial.println(text);
  }
}



I apologize my bad English, that's not my native language.

All replies are welcome

Robin2

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

If you need more help make sure to tell us what Arduinos you are using and how the nRF24s are powered.

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

Whandall

stopListening is to be called when you want to stop listening.
You have to call startListening to start listening.

So drop all the calls to stopListening in the transmitter sketch, as it never calls startListening.

The receiver sketch has a superfluous flush_rx, startListening takes care of any leftover packets IIRC.

What is the delay(100) at the end of setup of the transmitter good for?

Are you into voodoo? (all the useless magic spells you spice/obfuscate your code with)

But back to your problem:

You could try to lower the output power, sometimes near modules overpower each other.

Most communication problems are caused by a bad 3.3V supply for the NRF.
A capacitor directly on the NRF power pins can help, in addition a solid (own) 3.3V supply is better.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Go Up