Sending Sensor between NRF24L01 Transceivers

Hi, I am having trouble formatting the sensor data correctly, I keep getting the error of "initializer fails to determine size of 'text'" and it highlights line 36 which is "int text = tempF;". I am just confused and need to figure out what I am doing wrong. The output from the sensor of variable tempF would be something like "73.60" which is 5 bytes correct? So my question is from examples I have seen the text array is predefined and not a changing variable like mine would be since it changes every time I read the sensor. I have a DHT11 as a temperature sensor and NRF24L01 Transceivers communicating.


// NRF
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//create an RF24 object
RF24 radio(9, 8);  // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
int text[5]={0};

// DHT11
#include <dht11.h>
#define DHT11PIN 4
float tempC;
float tempF;
float humidity;
String dataString="";
dht11 DHT11;

void setup(){
  radio.begin();
  //set the address
  radio.openWritingPipe(address);
  //Set module as transmitter
  radio.stopListening();
}
void loop()
{
  //Send message to receiver
  int chk = DHT11.read(DHT11PIN);
  tempC=(float)DHT11.temperature;
  tempF= ((tempC*9)/5)+32;
  humidity=(float)DHT11.humidity;
  //dataString=String(tempF)+","+String(humidity);
  int text[] = tempF;
  radio.write(&text, sizeof(text));
  delay(1000);
}

If you want to send character (ASCII) data, then format the variable using dtostrf() for float variables, or itoa() for integers. Then send the text string. for example:

char text[10];
itoa(tempF, text, 10); //for integer ASCII representation
// or
dtostrf(tempF, 8, 2, text); //for float variable ASCII
radio.write((uint8_t *)text, strlen(text));  //may not need the "(uint8_t *)"

Or just send the binary data:

  radio.write((uint8_t *)&tempF, sizeof(tempF));
1 Like

Yes that does work, thank you. Question though, why do you have to put information into an array to send over the NRF24's? I am still kind of confused as to how it works.

You don't have to use an array, the NRF24L01+ can send any data (up to 32 bytes).
Arrays are handy if you only have one type of data (chars, ints, floats, etc.),
if you want to pack different types of data into one packet, a struct is the best method.

Cool didn't know that. Thank you

You can even send up to 32 bytes in the other direction with the same transaction
(the acknowledgment packet is filled with data). You have to load that data into the receiver
before a packet has to be acknowledged, so you can not directly 'answer',
but a direct back channel without switching modes in the code is very useful.

The data sheet is really worth a close look, if you want to use this very versatile chip.

Will do, thank you for your help. I was able to configure the data from the sensor as an int array and send that over thru the NRF24L01 which was my initial intention since I have 2 sensor values. Thank you for steering me in the right direction.