5

I started with building of the wireless temp/hygro/other values probes. I use 2 arduinos, both with nf24l01+ wireless transceivers, library used is rf24.h (https://github.com/maniacbug/RF24). Basically ping/pong test works for me - so each arduino communicates properly via nrf24l01+. I added dht22 temperature sensor and just for testing I started with sending structure:

typedef struct{
  int A; // just counter to see if receiving new data
  float B; // temperature
} data;

data payload;

I send it from Arduino1 like this:

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

Other Arduino2 receives the payload:

radio.read( &payload, sizeof(payload) );

This works perfectly and I am able to print the counter value as well as the temperature value on the oled display o Arduino2. The problem is when I add float C to the struct for sending/receiving hygrometer values. Then Arduino2 does not receive/display any valid hygro value, but there is just value of 0.00.

I think I know where my problem is - nrf24.h has possibility to set payload size for nrf24l01+ - both Arduinos have to use the same payload size (default is 16, min is 8, max is 32). I use 8 - as this looks to be the most reliable value when using larger distances between Arduinos. When I tried to set payload size to 32 on both Arduinos:

radio.setPayloadSize(32);

Then it works and I can receive and display counter, temp, hygro values. So it looks the nrf24l01+ sends a payload of either 8 or 32 bytes and when sending struct with INT, FLOAT, FLOAT - 8 bytes is not sufficient and 32 bytes of payload is needed. But when I will use many other values, I can reach also limit of 32 bytes payload.

I do not have much skills in C programming and also I do not fully understand how data packets are being transferred between nrf24l01+ modules- maybe I just need to adapt my send/receive code to handle sending of the larger structures. Maybe somebody could give me a hint.

  • 1
    It seems you have answered your own question: payload size is the key; you cannot transmit packets larger than the payload size. If your packets exceed the max 32 bytes size, then you will have to split them in smaller apckets and transmit them one by one. – jfpoilpret Feb 8 '15 at 11:07
  • I thought the nrf24 will take care and if I am sending more than payload size, it will send it piece by piece until all data is sent. And then the receiving side will receive it piece by piece until complete. So no way? I have to split the data manually into several "pieces" and then send more times? – user241281 Feb 8 '15 at 15:23
  • Ok, clear. Found it explained here as well -arduino.stackexchange.com/questions/8185/… – user241281 Feb 8 '15 at 15:36
  • correct, you must split it – Hayden Thring Mar 29 '15 at 23:12
3

Your payload is too big. You will have to split it to smaller pieces.

NOTE: If you'd use a library like RF24Mesh then you'd not have to worry about it.

0

as stated above, it all has to do with the size of your payload. To clarify things, you need to keep in mind how many bytes a certain data type uses/needs:

char: 1 byte int: 2 bytes float 4 bytes

(above is based on the Arduino reference, see https://www.arduino.cc/en/Reference/Float )

Thus, if you set payload size to 8 bytes in the NRF24L01 and then try to send a struct with int, float, float you will have 2 + 4 + 4 = 10 bytes, which does not fit in the payload size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.