My problem is that I have NRF24L01 sending and receive modules. At the moment the receiver is configured to receive two bytes. I want to rewrite the receiver code so that it can either receive two bytes as now or receive 13 bytes, depending on whether a condition is met. I can't use the NRF dynamic payload option (I think) because I don't have the option of reprogramming the existing transmitters which are stuck with the two byte payload.
Also, I can't use any of the NRF libraries because the SPI functionality within them seems to conflict with other libraries and peripherals. The existing transmitters are using ATTINY84s which makes it complicated.
So I thought that I would declare a dynamic array globally in the receiver code and then specify its size in setup(). I have never used dynamic variables so I'm not sure what I am doing wrong. At the moment I just want to set the size unconditionally in setup
robertjenkins:
So I thought that I would declare a dynamic array globally in the receiver code and then specify its size in setup().
I assume you are talking about the place where the Arduino will store the message that comes from the nRF24
If so just create a 32 byte array and make life simple.
Even if you do have some dynamic way to set the array size there is no practical way to use the extra memory elsewhere in your program. Dynamic memory allocation in the small memory of an Arduino brings with it a high risk that of a crash when you least expect it. Unlike on a PC there is no operating system to oversee things.
Thanks. I thought, from (possibly mis-) reading your excellent tutorial, that the payload array sizes on the sending and receiving ends had to match in order for anything to be received. If it's ok for the receiver side to be larger than the transmitter then there is no problem.
Edit - having tested this, it doesn't seem to work. If I declare the sending side as 2 bytes and the receiving as 13, nothing comes through.
The clunky way to solve this is to split up the 13 sending bytes into 7 chunks and send them sequentially
robertjenkins:
Also, I can't use any of the NRF libraries because the SPI functionality within them seems to conflict with other libraries and peripherals.
Could you please elaborate on that?
From my experience the NRF library uses SPI as intended and so does the NRF chip.
robertjenkins:
Thanks. I thought, from (possibly mis-) reading your excellent tutorial, that the payload array sizes on the sending and receiving ends had to match in order for anything to be received.
I expressed it that way for simplicity - it will cover most people's need.
What must match on both sides is the length (in bytes) that is used in the write() and read() commands.
Not being able to use two libraries on the ATTINY84 does not mean you can not use it on other Arduinos.
As I understood you post, you have to live with the senders, but are rebuilding the receiver.
I only build very small series if any, so I can use less cost optimized chips.