nRF24L01

Hi

Reading not works fine:

Code:

/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/

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

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/

byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving
bool role = 0;

void setup() {
  Serial.begin(115200);
  Serial.println(F("RF24/examples/GettingStarted"));
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
  
  radio.begin();

  // Set the PA Level low to prevent power supply related issues since this is a
 // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  radio.setPALevel(RF24_PA_LOW);
  
  // Open a writing and reading pipe on each radio, with opposite addresses
  if(radioNumber){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
  }else{
    radio.openWritingPipe(addresses[0]);
    radio.openReadingPipe(1,addresses[1]);
  }
  
  // Start the radio listening for data
  radio.startListening();
}

void loop() {
  
  
/****************** Ping Out Role ***************************/  
if (role == 1)  {
    
    radio.stopListening();                                    // First, stop listening so we can talk.
    
    
    Serial.println(F("Now sending"));

    unsigned long start_time = micros();                             // Take the time, and send it.  This will block until complete
     if (!radio.write( &start_time, sizeof(unsigned long) )){
       Serial.println(F("failed"));
     }
        
    radio.startListening();                                    // Now, continue listening
    
    unsigned long started_waiting_at = micros();               // Set up a timeout period, get the current microseconds
    boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not
    
    while ( ! radio.available() ){                             // While nothing is received
      if (micros() - started_waiting_at > 200000 ){            // If waited longer than 200ms, indicate timeout and exit while loop
          timeout = true;
          break;
      }      
    }
        
    if ( timeout ){                                             // Describe the results
        Serial.println(F("Failed, response timed out."));
    }else{
        unsigned long got_time;                                 // Grab the response, compare, and send to debugging spew
        radio.read( &got_time, sizeof(unsigned long) );
        unsigned long end_time = micros();
        
        // Spew it
        Serial.print(F("Sent "));
        Serial.print(start_time);
        Serial.print(F(", Got response "));
        Serial.print(got_time);
        Serial.print(F(", Round-trip delay "));
        Serial.print(end_time-start_time);
        Serial.println(F(" microseconds"));
    }

    // Try again 1s later
    delay(1000);
  }



/****************** Pong Back Role ***************************/

  if ( role == 0 )
  {
    unsigned long got_time;
    
    if( radio.available()){
                                                                    // Variable for the received timestamp
      while (radio.available()) {                                   // While there is data ready
        radio.read( &got_time, sizeof(unsigned long) );             // Get the payload
      }
     
      radio.stopListening();                                        // First, stop listening so we can talk   
      radio.write( &got_time, sizeof(unsigned long) );              // Send the final one back.      
      radio.startListening();                                       // Now, resume listening so we catch the next packets.     
      Serial.print(F("Sent response "));
      Serial.println(got_time);  
   }
 }




/****************** Change Roles via Serial Commands ***************************/

  if ( Serial.available() )
  {
    char c = toupper(Serial.read());
    if ( c == 'T' && role == 0 ){      
      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
      role = 1;                  // Become the primary transmitter (ping out)
    
   }else
    if ( c == 'R' && role == 1 ){
      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));      
       role = 0;                // Become the primary receiver (pong back)
       radio.startListening();
       
    }
  }


} // Loop

Rekimo:
Reading not works fine:

That does not provide any useful information from which to help you.

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

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

...R


SimpleTx.ino and SimpleRx.ino

@Rekimo, I don't know what you are trying to do but it obviously isn't working.

In case you are trying to include an image have a look at this Simple Image Guide

But please don't post an image of text. Just copy and paste the text.

...R

... rpm .. open image in new tab ...

rpm lel :confused: … Right-Click :stuck_out_tongue:

and after some time:

download.png

And next:

Image from Reply #9 so we don't have to download it. See this Simple Image Guide

...R

Now we can see the image. But way back in Reply #4 I asked you NOT to post an image of text

In any case it seems like your Arduino is able to communicate with the nRF24 it is attached to.

...R

Then why this isnt works fine? Only tx fails... ex sometimes can receive text

Rekimo:
Then why this isnt works fine? Only tx fails... ex sometimes can receive text

You need two Arduinos and two RF24s to send and receive.

Have you tried the connection test program for both of them? And remember that that test does not tell if the wireless part of the nRF24 is working.

Have you followed the instructions in my Tutorial exactly?

If you need more help you need to provide a lot more information

  • Exactly what Arduino boards are you using?
  • Are you using the High Power nRF24s (with external antenna) or the low power modules with the PCB antenna?
  • Do you have 10µF capacitors across Vcc and GND for the nRF24s?
  • Post both of the programs that YOU have uploaded to your two Arduinos and also post a sample of the output from each of them.
  • Do you have a third nRF24 so you can check if one of them is faulty?

...R

Im using arduino nano and uno
Nrf powered 3.3v
Pcb antenna
Nope no capacitors
This same like in your tutorial(simplerx and simpletx)
I have only two nrf

Rekimo:
Im using arduino nano and uno
Nrf powered 3.3v

You did not say if they are genuine Arduino boards? Clones many not be able to power an nRF24. Even a genuine nano may not have enough 3.3v current. Try powering the nRF24s from pairs of AA alkaline cells (3v) with the nRF24 GND connected to the Arduino GND.

Nope no capacitors

Get some. They may not solve the problem but here is no point complaining about failure if you don't have them.

This same like in your tutorial(simplerx and simpletx)

I asked you to post the programs that YOU have uploaded. I know that my programs work.

I have only two nrf

If one of them is faulty you have no way of knowing which one or even if that is the problem, Get a few more.

...R

Arduino clones

Rekimo:
Arduino clones

If you can't be bothered to respond to all my comments I don't see why I should waste my time.

You are the person who wants help yet it seems to me I have written more text in this Thread than you have.

...R

I am currently at work…
I will respond to all yours questions later

I have only clone of arduino … its cheaper :stuck_out_tongue:

when nrf is connected the meter indicates 3.25v(Arduino Nano)
on UNO is 3.26v

if u want i can use alkaline cells but in my opinion wiith this voltage module should be works fine… idk what is wrong…

code, what i use:

RX:

// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}

and TX:

// SimpleTx - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }

    delay(2000);
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

CheckConnection.ino:

UNO:

CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24


STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0

RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0x0000000106

RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6

TX_ADDR	         = 0xe7e7e7e7e7

RX_PW_P0-6	 = 0x00 0x20 0x00 0x00 0x00 0x00

EN_AA            = 0x3f

EN_RXADDR	 = 0x03

RF_CH		 = 0x4c

RF_SETUP	 = 0x07

CONFIG		 = 0x0f

DYNPD/FEATURE	 = 0x00 0x00

Data Rate	 = 1MBPS

Model		 = nRF24L01+

CRC Length	 = 16 bits

PA Power	 = PA_HIGH



AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate


STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0x0000000106

RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6

TX_ADDR		 = 0xe7e7e7e7e7

RX_PW_P0-6	 = 0x00 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_HIGH

NANO:

CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24


STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0

RX_ADDR_P0-1	 = 0x000000010b 0x0000000106


RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6


TX_ADDR	         = 0x000000010b


RX_PW_P0-6	 = 0x20 0x20 0x00 0x00 0x00 0x00


EN_AA            = 0x00


EN_RXADDR	 = 0x03

RF_CH		 = 0x4c

RF_SETUP	 = 0x07

CONFIG		 = 0x0c


DYNPD/FEATURE	 = 0x00 0x00

Data Rate	 = 1MBPS

Model		 = nRF24L01+

CRC Length	 = 16 bits

PA Power	 = PA_HIGH



AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate


STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x000000010b 0x0000000106


RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6


TX_ADDR		 = 0x000000010b


RX_PW_P0-6	 = 0x20 0x20 0x00 0x00 0x00 0x00

EN_AA		 = 0x00


EN_RXADDR	 = 0x03

RF_CH		 = 0x4c

RF_SETUP	 = 0x27

CONFIG		 = 0x0c

DYNPD/FEATURE	 = 0x00 0x00

Data Rate	 = 250KBPS

Model		 = nRF24L01+

CRC Length	 = 16 bits

PA Power	 = PA_HIGH

maybe i must buy another nrf to check it…
always is Tx failed
but sometimes the next one can receive message