0

I'm trying to send data from one Arduino board to another using NRF24L01 connect to the two ends of the two Arduino boards. The Tx blinks in the transmitting end(Arduino board 1) but the receiving end(Arduino board 2) is not getting any value from it. Here is my code.

Transmitting end (Arduino board 1)

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

RF24 myRadio(0, 1);
byte addresses[][6] = {"0"};

struct package
{
    int id = 1;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "Geographic coordinates";
};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openWritingPipe(addresses[0]);
    delay(1000);
}

void loop()
{
    myRadio.write(&data, sizeof(data));

    Serial.print("\nPackage:");
    Serial.print(data.id);
    Serial.print("\n");
    Serial.println(data.longitude);
    Serial.println(data.latitude);
    Serial.println(data.text);
    data.id = data.id + 1;
    data.longitude = data.longitude + 0.1;
    data.latitude = data.latitude + 0.1;
    delay(1000);
}

Receiving end (Arduino board 2)

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

RF24 myRadio(7, 8);
struct package
{
    int id = 0;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "empty";
};

byte addresses[][6] = {"0"};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openReadingPipe(1, addresses[0]);
    myRadio.startListening();
    delay(1000);
}

void loop()
{

    if (myRadio.available())
    {
       while (myRadio.available())
       {
           myRadio.read(&data, sizeof(data));
       }
        Serial.print("\nPackage:");
        Serial.print(data.id);
        Serial.print("\n");
        Serial.println(data.longitude);
        Serial.println(data.latitude);
        Serial.println(data.text);
    }

}

This is how i connected the Arduino and NRF24L01 enter image description here

Any reason why im not getting the the data from the transmitting end?

  • try myRadio.readBytes(&data, sizeof(data)); What nRF24 library you use? – Juraj Nov 16 '18 at 13:00
  • @Juraj RF24.h by TMRh20 – TRomesh Nov 16 '18 at 13:53
  • it doesn't implement Stream so it doesn't have readBytes – Juraj Nov 16 '18 at 13:55
  • @Juraj you mean like myRadio.available() >= sizeof(data) ? – TRomesh Nov 16 '18 at 14:00
  • it will not work. I deleted the comment. the struct is bigger then the receive buffer – Juraj Nov 16 '18 at 14:02
2

Check the reading and writing pipe addresses.

First, the default is 0xE7E7E7E7E7 for pipe 0 (RX_ADDR_P0) and 0xC2C2C2C2C2 for pipe 1 (RX_ADDR_P1), see the data sheet. Check that the transmitter (TX) address is the same as the receiver (RX) pipe address.

Secondly, you should not set the pipe address to 0x0 even if that's common between the TX and RX. This note comes from the data sheet:

Addresses where the level shifts only one time (that is, 000FFFFFFF) can often be detected in noise and can give a false detection, which may give a raised Packet Error Rate. Addresses as a continuation of the preamble (hi-low toggling) also raises the Packet Error Rate

  • Actually the pipe address is "0" which is a string with implicit null terminator, which corresponds to 30 00 - which is still as bad. Also I don't know how the library fills up the missing 3 bytes from the address. In any case not knowing the real address can be troublesome. Better try something like "Link1" or something with 5 characters. – Kwasmich Jan 10 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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