Go Down

Topic: nrf24l01 not working with 2 Arduino uno (Read 658 times) previous topic - next topic

Jonathan2003

Hello, I can't get my nRF24 modules to work, I know it is not the modules because I have bought more modules and they are also not working. These are my connections. GND - gnd, VCC - 3.3V, CE - 5, CSN - 10, SCK - 13, MOSI - 11, MISO - 12. I have also tried switching CE to 7 and CSN to 8 but no success. I am using the code from Robin2.

TRANSMITTER
Code: [Select]
// SimpleTx - the master or the transmitter

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



#define CE_PIN   5
#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);


printf_begin();
    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() {
radio.stopListening();

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


RECIEVER
Code: [Select]
// SimpleRx - the slave or the receiver

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

#define CE_PIN   5
#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 am also using the library from Robin2's nRF24 demo.
I have the VCC connected to 3.3V and I have checked that my Arduino gives of 3.3V. When I run the SimpleTx code I get "Data Sent Message 0  Tx failed" in the Serial Monitor. When I run the SimpleRx code I get "Data received" in the Serial Monitor. I do not get any message in the Arduino logs other than "avrdude done.  Thank you." so I guess there are no syntax problems. If you could help me out I would greatly appreciate it. Thanks in Advance :). I used this library - https://tmrh20.github.io/RF24/ and I got the code from here - https://forum.arduino.cc/index.php?topic=421081.0

Robin2

I see you have changed the I/O pins for CE and CSN. I have not checked if you have changed anything else.

Start by getting my examples to work without any changes.

Have you used the connection test program to make sure your Arduino is communicating with its nRF24 - I think it is in Reply #29 in the Tutorial.

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

Jonathan2003

Thanks for the reply, I tried the check connection code and I am getting this


"

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       = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1    = 0x0000000000 0x0000000000
RX_ADDR_P2-5    = 0x00 0x00 0x00 0x00
TX_ADDR       = 0x0000000000
RX_PW_P0-6    = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA       = 0x00
EN_RXADDR    = 0x00
RF_CH       = 0x00
RF_SETUP    = 0x00
CONFIG       = 0x00
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model       = nRF24L01
CRC Length    = Disabled
PA Power    = PA_MIN


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

STATUS       = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1    = 0x0000000000 0x0000000000
RX_ADDR_P2-5    = 0x00 0x00 0x00 0x00
TX_ADDR       = 0x0000000000
RX_PW_P0-6    = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA       = 0x00
EN_RXADDR    = 0x00
RF_CH       = 0x00
RF_SETUP    = 0x00
CONFIG       = 0x00
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model       = nRF24L01
CRC Length    = Disabled
PA Power    = PA_MIN



"

For one of the nRF24

and

"

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    = 0x4141417852 0x4141417852
RX_ADDR_P2-5    = 0xc3 0xc4 0xc5 0xc6
TX_ADDR       = 0x4141417852
RX_PW_P0-6    = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA       = 0x3f
EN_RXADDR    = 0x03
RF_CH       = 0x4c
RF_SETUP    = 0x07
CONFIG       = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model       = nRF24L01+
CRC Length    = 16 bits
PA Power    = PA_MAX


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    = 0x4141417852 0x4141417852
RX_ADDR_P2-5    = 0xc3 0xc4 0xc5 0xc6
TX_ADDR       = 0x4141417852
RX_PW_P0-6    = 0x20 0x20 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



"

For the other nRF24

Robin2

The first one is not communicating properly. An incorrect connection or a loose connection is often the cause.

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

srnet

I know it is not the modules because I have bought more modules and they are also not working.
The only way you will know its not the modules is when you have two that are actually working.

Buying more modules cannot guarantee that the modules you bought are good.
http://www.50dollarsat.info/
http://www.loratracker.uk/

Kintara

I too was having trouble with the NRF24L01+ modules and it all boiled down to incorrect wiring and poor connections with the fly leads  (especially with a breadboard). Check and check again. One of them is working so you know the script is good on that arduino; try swapping the NRF24's and see if the same arduino still works. If it does that shows the NRF24's are ok.

Jonathan2003

Thank you for the replies, I finally got it working, I had to connect the nRF's to the 5V on the Arduino Uno.

Robin2

Thank you for the replies, I finally got it working, I had to connect the nRF's to the 5V on the Arduino Uno.
I think that will fry the nRF24s. My advice is to STOP IMMEDIATELY.

Have you tried powering the nRF24s with a pair of AA alkaline cells (3v) - that works well for me. Some Arduinos do not provide enough 3.3v current.

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

Go Up