Notifications
Clear all

Need help with nrf24L01

69 Posts
10 Users
12 Likes
5,172 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@gkar2287 In the meanwhile, can you accomplish anything with the example programs that come with the library?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@gkar2287 I posted 2 separate sketches. Run one on one mega and the other on a separate mega. You can see the break in the code where I say, "Here is the code for the transmitter" Cut and paste each section into a new arduino sketch and give each a name like RadioClient_Transmitter.ino and RadioReceiver_Server.ino.

Connect the pins thus: CE 8 left most pin on the adapter to pin 8

CSN 53 2nd to the left on the adapter to pin 53

SCK 52 3rd pin on adapter to mega pin 52

MOSI 51 4th pin from left to mega 51

MISO 50 5th from left, 2nd from right on adapter to pin 50. Rightmost pin on adaptor not used

Voltage & gnd on adapter to arduino 5v and gnd

This will work. I wrote this basic "can you make 2 radios talk" just for you, and then tested it. The transmitter will send "Hello boom" to the receiver. Receiver will return "Message received" You canh ook up some LEDs also but you don't need to. I'd say don't bother for now. The programs work perfectly fine with just the radios hooked up. Run the programs on 2 different computers with serial monitors turned on and you'll see the print output.

If you have problems compiling or running you need to explain the error. "I'm getting multiple faults" is just saying, "It doesn't work." The IDE will produce specific error messages like "redLed not declared in this scope." Photo of the setup below.

IMG 0735

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@eliza I tried your sketches also, the second one is cut off, the last statement is missing the ; then the led routines are missing but I copied them from the first sketch, then it failed on a missing variable (don't remember which one) something like a buffer.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@eliza 

The second sketch (the transmitter) that you posted in 

https://forum.dronebotworkshop.com/postid/28446/

is incomplete. The pasted sketch has been truncated and the end of the sketch is missing.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@will Beat you to it buddy, you are slowing down!

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@zander 

Not at all, I realize that you were the first one to mention it (kudos for that). But it appears that Eliza believes that the sketch is OK, so I'm simply adding another voice to the chorus to try to bring the artificially shortened sketch to his attention.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@gkar2287 Oops, I steered you wrong on the code. I somehow pasted 2 chunks of code together.

Here is the correct code for the transmitter. Sorry for the confusion. I think I have it right this time. I just tested it and it compiles cleanly.  I removed the LED code and all the spurious code in the main loop. That code was commented out, but now there is nothing there to confuse you. Let me know if you want to use LEDs after you get the radios talking.

/*****************************************
* NRF24L01 boom transmitter SANDBOX
* this sketch is for the mega
*
 https://create.arduino.cc/projecthub/muhammad-aqib/nrf24l01-interfacing-with-arduino-wireless-communication-0c13d4 
**************************************** */

#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>

#define CE 8
#define CSN 53
#define MOSI 51
#define MISO 50
#define SCK 52

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Create an instance of the radio driver
RH_NRF24 RadioDriver(CE, CSN);
RHReliableDatagram radioManager(RadioDriver, CLIENT_ADDRESS);

uint8_t outputData[] = "Hello boom from the mega.";

uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

//boolean debug = false;
boolean debug = true;

/////////////////////////////////////////////////////////////////
void setup() {

boolean transmissionConfirmed = false;
boolean radioInitOk = false;
Serial.begin(9600);
Serial.println("Enter setup boom controller transmitter build 4.27.22.1 ");

while (!radioInitOk){
if (radioManager.init()) {
radioInitOk = true;
Serial.println("radio init OK");
} // if radioInit OK
else {
Serial.println("radioManager.init failed");
} // else
delay(2000); // try the radio again in 2 seconds
}

while (! transmissionConfirmed ) {
// Send default message to radioManager
Serial.println("Attempting transmission to server");
if (radioManager.sendtoWait(outputData, sizeof(outputData), SERVER_ADDRESS)) {
Serial.println("Waiting for reply");
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (radioManager.recvfromAckTimeout(buf, &len, 2000, &from)) {
transmissionConfirmed = true;
Serial.print("got reply from: ");
Serial.print(from, HEX);
Serial.print(" : ");
Serial.println((char*)buf);
}
else {
Serial.println("No reply, is nrf24_reliable_datagram_server running?");
} // else not radioManager.recvfromAck
} // radioManager.sendtoWait
else
Serial.println("radioManager.sendtoWait failed");
delay(1000); // retry after 1 second
} // while not transmission confirmed

Serial.println("Exiting setup.");
} // setup

////////////////////////////////////////////////////////////////////
void loop() {

} // main loop

 


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@will Thanks for catching this. I think I accidentally pasted 2 buffers together? I just reposted the code.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@will Hi Will, thanks for catching the code error. I reposted it and also let gkar know.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@eliza 

Ron actually caught it first, I was just waving my arms to get your attention 🙂

 

All's well that ends well.

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@zander Thanks for your help. I moved the code from a linux machine to a stick drive to windows, to TextPad to the forum, and goofed somewhere along the way.

Correct code reposted. I removed the LED stuff. The main loop is just empty but I had left a commented out chunk there. I am only trying to get one radio to talk to the other and nothing more. Both main loops are empty in my example.


   
Ron reacted
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

To anybody, How do I edit my post with the bad code? I would like to get it off the site for everyone's benefit? I can't find an "edit my post" control anywhere. Thanks.

Ok, check that. As soon as I posted this message it appeared with an edit option. This sentence is new from just a moment ago. But the one with the bad code doesn't show an edit option.

???

Thanks everyone.

2nd edit. The one I WANT to edit shows "reply, quote, report" only. No edit nor delete option.

This post was modified 2 years ago 3 times by Eliza

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@eliza 

I believe the edit/delete window is only open for about an hour. After that it's permanent unless removed by a moderator.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@will @eliza Yes, it's a weakness of this forum. I can easily guess why late editing/deleting is removed, but perhaps an author only tool that basically says see the post at ........ for corrected code. Or just alow editing forever as long as it's highlighted and the original still showing but marked as replaced.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@will This is probably necessary for forums that are not as amiable as this one, so that people that post hateful messages can't delete them later and then deny it. Thanks for your reply.


   
ReplyQuote
Page 3 / 5