nRF24l01 library functions

I have the nRF24l01 library for Arduino. I am trying to write my own code, but that's hard when you don't know how the library's functions work. So I was wondering if someone could give me a link to how to use the functions, or tell me how to use the common ones like the .read() and .write() functions. For example:

unsigned long time = millis(); printf("Now sending %lu...",time); bool ok = radio.write( &time, sizeof(unsigned long) );

I'm sure this is a common c+ thing, but why is there "&" in front of "time" and, if I can, how do I send and receive Strings?

Thanks for any help!

Try this

https://youtu.be/o8Ever-0tss

Or this video helps you figure out what your library functions are

https://youtu.be/tcBmE0BsHss

The documentation for the TMRh20 version of the RF24 library is here

You should also study the Nordic nRF24L01+ datahsheet.

The pair of programs in this link may be helpful.

...R

If you want to write your own nrf code i would suggest starting with a simpler code, this might be what you are looking for. This code is a lot easier to follow and you can easily follow the code and see what is happening.

NRF24L01_Demo_For_Arduino_v11.zip (8.73 KB)

Thanks guys! I'll have a look at all the stuff you gave me

I was looking at the documentation for the write() function and I have a simple question. If I did this:

data = 2;
radio.stopListening();
radio.write(&data,sizeof(data));
radio.startListening();

That would send a 2, right?

Also, what if I put 2 of them, like this:

data = 2;
data2 = 5
radio.stopListening();
radio.write(&data,sizeof(data));
radio.write(&data2,sizeof(data2));
radio.startListening();

How would the other nRF24l01 module receive that?

As 2 different messages sent just after each other... the receiver might miss the second message depending on the receiver code.

nick13579: I was looking at the documentation for the write() function and I have a simple question. If I did this:

data = 2;
radio.stopListening();
radio.write(&data,sizeof(data));
radio.startListening();

That would send a 2, right?

You have not posted a complete program so I do not know what data type you have defined for the variable data. The sizeof() function detects the length of the variable - a byte is 1 byte long, an int is 2 bytes long etc.

You MUST have a matching data type on the receiving side because what the nRF24 actually sends is a series of bytes that is sizeof() long. If you try to stuff 2 bytes into 1 byte at the receiving end you will get garbage.

If you use an array you can send several pieces of data in one message. The max length of a single message is 32 bytes. The code in the link I gave you uses arrays.

...R

Ok thanks

Sorry for the late reply

One other quick question. What is the first parameter used for in openReadingPipe()?

The first number is the PIPE. The nRF24 can listen on 6 pipes at the same time (like having 6 telephones and someone to answer each one). Normally I would just use Pipe 1 - I have not needed to use multiple Pipes in my projects.

The second number is the address - analagous to a telephone number. Unfortunately many example programs use the name "pipe" for the variable that holds the address even though the Pipe is a quite separate concept from the address.

...R