Go Down

Topic: connection between two NRF24L01 not working (Read 320 times) previous topic - next topic

Misel

Hi, I am trying to connect two arduinos using NRF24L01 on each.

One of them is transmitter and this is code and radio.printDetails from him:

Code: [Select]

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

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

const byte address[6] = "00001";

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

  printf_begin();
  radio.printDetails();
  Serial.println(radio.available());
}

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


Code: [Select]

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x3130303030 0xc2c2c2c2c2
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0x3130303030
RX_PW_P0-6 = 0x20 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x27
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX



Here is my code and printDetails from sender:

Code: [Select]

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

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

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.startListening();

  printf_begin();
  radio.printDetails();
}

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


Code: [Select]

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x3130303030 0x3130303030
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe7e7e7e7e7
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x27
CONFIG = 0x0f
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX



Can somebody tell me why there is no established connection between this two arduinos?

Robin2

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

Misel

I tried Simple one way transmission example and I am getting only Data Received message in receiver serial monitor. Message is not reading, why?

Robin2

#3
Dec 25, 2017, 10:47 am Last Edit: Dec 25, 2017, 10:48 am by Robin2
I tried Simple one way transmission example and I am getting only Data Received message in receiver serial monitor. Message is not reading, why?
Post the code that YOU uploaded to YOUR two Arduinos.
Post a sample of the output from both programs.

What Arduino boards are you using?
Have you got 10µF capacitors across Vcc and GND for the nRF24 modules?
Have you a spare nRF24 module in case one of them is faulty?

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

Misel

Okey, I know used 10µF capacitors across Vcc and GND and I looks like message is sending and receiving but in receiver serial monitor message is unreadable, like symbol string. Baud value is set same in code and in serial monitor.

Here is my code of sender and receiver and it's output.

Sender code

Code: [Select]

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

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

struct package
{
  int id=1;
  float temperature = 18.3;
  char  text[100] = "Text to be transmitted";
};


typedef struct package Package;
Package data;


void setup()
{
  Serial.begin(9600);
  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.temperature);
  Serial.println(data.text);
  data.id = data.id + 1;
  data.temperature = data.temperature+0.1;
  delay(1000);

}



Receiver Code
Code: [Select]

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

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

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



typedef struct package Package;
Package data;

void setup()
{
  Serial.begin(9600);
  delay(1000);

  myRadio.begin();
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ;
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}


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.temperature);
    Serial.println(data.text);
  }

}


Sender serial monitor output

Code: [Select]

Package:219
40.10
Text to be transmitted

Package:220
40.20
Text to be transmitted

Package:221
40.30
Text to be transmitted

Package:222
40.40
Text to be transmitted



Receiver serial monitor output

Code: [Select]

Package:3840
0.75
?/???=?????????

Package:3840
0.75
?/???=?????????

Package:10752
0.75
???}?~~?

Package:0
0.00
(

Package:32298
ovf
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮


Robin2

The programs in Reply #4 are not the programs from my Tutorial.

Wireless problems can be very difficult to debug so get get the Tutorial example to work without any changes before you start adding in other stuff.

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

Misel

Okey, so I am using your code now.

Code from this post http://forum.arduino.cc/index.php?topic=421081.msg2899627#msg2899627

and I am getting on transmitter serial monitor:

Code: [Select]

SimpleTx Starting

SimpleTx Starting


and on receiver serial monitor:

Code: [Select]

Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
.
.
.

Robin2

and on receiver serial monitor:
If the words "Data Received" are repeating very quickly it is probably due to incorrect wiring between the Arduino and the nRF24 or perhaps that the nRF24 is faulty.

When things are working properly the data should be received about once per second.

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

Go Up