nRF24 / RF24

OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices
https://nrf24.github.io/RF24
GNU General Public License v2.0
2.23k stars 1.02k forks source link

Does RF24 always need char sent and never string ? #611

Closed adrianTNT closed 4 years ago

adrianTNT commented 4 years ago

I have a question, I am not very experienced with Arduino. When sending and receiving data with the RF24 library:

radio.write(&my_data, sizeof(my_data));

Does my_data here always needs to be of char type ? And if not, how would that line look if my_data is a string ?

I am asking because I find it easier to append and do other operations on string rather than char.

Thank you.

Avamander commented 4 years ago

Does my_data here always needs to be of char type ?

It's not char, it's a char array with a specific maximum size depending on the configuration of your radio (see documentation on payload size for that information), and yes, it needs to be of that type because a bunch of bytes are roughly speaking the only thing that are transmitted by the radio.

And if not, how would that line look if my_data is a string?

The same way. But before that line you should be filling my_data with an appropriately sized part of your String.