using nRF24L01

Hello all
I try to use nRF24L01. Hardware is same as a picture, and code is this.

//transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio (7,8);
const byte adr[6] = “00001”;
void setup() {
radio.begin();
radio.setRetries(15,15);
radio.openWritingPipe(adr);
radio.stopListening();
}

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

//Receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio (7,8);
const byte adr[6] = “00001”;
void setup() {
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,adr);
radio.startListening();
}

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

But I can’t get “Hello world” in my Serial monitor. What’s the problem???

Main reasons for failing NRFs (besides programming errors) in descending frequency of occurrence

  • bad wiring
  • bad power supply
  • missing capacitor near the NRF power pins
  • usage of too much power over short distance Reading more data than was sent (32 vs 13) could be another problem, but even if it were not, I would not do such a strange thing.

Maybe have a look at this Simple nRF24L01+ Tutorial - the examples do work.

…R

I copied that examples but it doesn't work too. I checked nRF24L01 status by radio.printDetails(); and the result is this:

Test connection to modules

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0 RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2 RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6 TX_ADDR = 0xf0f0f0f0e1 RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00 EN_AA = 0x3f EN_RXADDR = 0x02 RF_CH = 0x4c RF_SETUP = 0x07 CONFIG = 0x0f DYNPD/FEATURE = 0x3f 0x04 Data Rate = 1MBPS Model = nRF24L01+ CRC Length = 16 bits PA Power = PA_MAX

Something wrong in there?

francejs: RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2 TX_ADDR = 0xf0f0f0f0e1

Something wrong in there?

These values are not possible with your sketch

 const byte adr[6] = "00001";

nor with Robin2's.

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

I used code from another person so Something wouldn’t match with the first code. This is the code for radio.printDetails();

/**

  • First test

*/

#include <SPI.h>
#include <RF24.h>
#include “printf.h”

//
// Hardware configuration
//

// Configure nRF24L01 radio module on SPI bus plus pins 8 for CE & 9 for CS
// arguments are (ce, cs)

RF24 radio(8,9);

//
// Set transmit and receive addresses
//

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup(void)
{

Serial.begin(9600);
printf_begin();
printf("\n\rTest connection to modules\n\r");

//
// Setup and configure rf radio
//

radio.begin();

// Set the TX and RX addreses in the module

radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);

// radio.setDataRate( RF24_2MBPS ) ;
// radio.setPALevel( RF24_PA_MAX ) ;
radio.enableDynamicPayloads() ;
radio.setAutoAck( true ) ;
radio.powerUp() ;
radio.startListening();

//
// Print out the configuration of the rf unit for debugging
//

radio.printDetails();
}

void loop(void)
{
}

francejs:
I copied that examples but it doesn’t work too.

“it doesn’t work” does not provide any information I can use to help you. The examples do work for me and for others.

If you post the actual code that YOU uploaded and explain exactly what output you get from the two Arduinos I will try to help.

…R

Tx code is this

// 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");
}
}

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

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

and Rx code is this

// 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;
}
}

I put this code to each arduino but tx monitor keep saying “Data send message 0 TX failed” and rx monitor says nothing. I think Rx and Tx doesn’t connected.

I’m sorry that I asked in wrong way. My english ability is not good…

please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum When you don’t use the code button it is very hard to copy your code.

In any case, your code does seem to be the same as my original. If it is not working that suggests a wiring problem or a power problem. Your diagram in your Original Post shows you using pins 6 and 7 whereas my examples use 9 and 10

It is not essential to use pins 9 and 10 but it is essential for pin 10 to be set for OUTPUT even if it is not being used with the nrf24

Have you got 10µF capacitors across Vcc and GND for the nRF24s? Sometimes that is essential.

…R