Author Topic: Setting Up the nRF24L01 for Transmitting, and Receiving  (Read 16584 times)

0 Members and 2 Guests are viewing this topic.

Offline tonytruong

  • Newbie
  • Posts: 7
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #25 on: March 04, 2024, 09:48:34 pm »
Thanks for a quick reply MarkF.
As had trouble to make it to work with my assembly code, I have restarted to test with the simple code from "How to Mechatronis" from Mr. Dejan Nedelkovski's code to verify/understand the reason why.
Unfortunately it behaves the same way, only in direction from elder UNO to younger UNO as I have described in the previous post.
Here is the code ...
Note: Mr. Dejean Nedelkovski uses "Arduino Mega + nRF24L01" and "Arduino UNO/Nano + nRF24L01". I think the code is common in all platform.
Thank as lot.
Tony Truong

======
Transmitter Code
/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

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

const byte address[6] = "00001";

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

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

=====
Receiver Code
/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.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_MIN);
  radio.startListening();
}

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

 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #26 on: March 04, 2024, 11:18:44 pm »
What I have done is at a much lower level talking to the nRF transceiver directly without any libraries.

I leave it to you to debug Mr. Nedelkovski's code. 
At a glance, I wouldn't think the address for both radios should be the same
   ( i.e.  const byte address[6] = "00001"; )

I would start with the 'GettingStarted.ino' example in the RF24 example section.
I spent a lot of time with the RF24 library and never really figured out how they did their addressing. 

The nRF24L01 expects pipe #0 receive address and the transmit address to always be the same.
I then used pipe #1 as the receive of the other transceiver.  For example:

  nRF #1
     RX_ADDR_P0 = E7E7E7E7E7h
     RX_ADDR_P1 = C2C2C2C2C2h
     TX_ADDR    = E7E7E7E7E7h

  nRF #2
     RX_ADDR_P0 = C2C2C2C2C2h
     RX_ADDR_P1 = E7E7E7E7E7h
     TX_ADDR    = C2C2C2C2C2h

The Arduino RF24 library hides the real addressing from you.


P.S.  Please use the code tag when posting code (i.e. the '#' button above the edit box.)
      Or enclose your code within the html like "code", "/code" within square brackets.
 

Offline tonytruong

  • Newbie
  • Posts: 7
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #27 on: March 07, 2024, 01:23:02 pm »
Good morning MarkF.
Thank you very much for your helps.
I have followed your suggestions and I have successfully made 2 x nRFs talk to each other with "assembly code" now.
I really appreciate your insights and your "open mind" to help out people.
Have a good day.
Tony Truong
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #28 on: March 07, 2024, 06:31:48 pm »
I've been doing a little experimenting myself.
I was wrong about the addressing needing to be different.
Two nRF24L01+ transceivers addressed and configured exactly the same will communicate with each other using pipe 0.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf