Display temperature and humidity separately on LCD I2C

Hello, in this project I am using 2 Arduino boards Transmitter and Receiver. I am planing to transmit temperature and humidity via RF24L01 radio module. Everything works fine, but it would be preferable to display temperature and humidity separately. Does anybody know how to menage it.

Here is the sketch for Transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include "DHT.h"

#define DHTPIN A0         // what pin we're connected to
#define DHTTYPE DHT11     // DHT 11

//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

float h;
float t;

RF24 radio(8, 10);     //digital pins for CE and SCN

const byte rxAddr[6] = "00001";

void setup()
{
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  
    // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  h = dht.readHumidity();
  t = dht.readTemperature();
  
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } 
  
  const float dataTemp = t;
  radio.write(&dataTemp, sizeof(dataTemp));
  
//  delay (1000);
  
  const float dataHumid = h;
  radio.write(&dataHumid, sizeof(dataHumid));
  
  delay(1000);
  
  dht.begin();

}

Here is the sketch for Receiver:

#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

RF24 radio(8, 10);     //digital pins for CE and SCN

const byte rxAddr[6] = "00001";

void setup()
{
  lcd.begin(16,2);         // initialize the lcd for 16 chars 2 lines
  lcd.setCursor(2,0);
  lcd.print("METEO STATION");
  lcd.setCursor(5,1);
  lcd.print("SETUP");
  delay(2000);
  lcd.clear();
  while (!Serial);
  Serial.begin(9600);
  
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    float data = 0;
    radio.read(&data, sizeof(data));
  
    Serial.print(data);
    Serial.print("     ");
    lcd.setCursor(4,1);
    lcd.print(data,0);
    
      delay(500);
//    Serial.print("C*");
//    Serial.print("%");
  }
}

Your sender sends two packets. Your receiver receives one packet (at most) per pass through loop().

Your packets should contain something that indicates whether it is a temperature or a humidity. Your receiver should look at the packet to determine which line to display it on.

Thank you. I guess it's possible to make it if a receiver sends back a message that indicates the end of temperature transmission and pass to humidity data collection. Easy way to saying that.

Why do you need to pass the data as a float, and then convert the float to a string to be able to display it?

Why not pass the data as a string (like "T:72.0" or "H:37.0") and KNOW which line to display the data on?

How tu put a variable such as or inside a String?

How tu put a variable such as or inside a String?

Do NOT use Strings. There is no reason to.

The string (lower case s) that you want to send is a known size. So, allocate a char array of the proper size and use dtostrf() to convert floats to strings or itoa() to convert ints to strings, and/or sprintf() to combine the strings with literals.

I did something like this for transmission

void loop()
{
  
    // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  h = dht.readHumidity();
  t = dht.readTemperature();
  
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } 
 
  float dataTemp = t;
  dtostrf(dataTemp,3,2,stringT);          //Conversion float temp to string 
  radio.write(&stringT, sizeof(stringT));
  
  float dataHumid = h;
  dtostrf(dataHumid,3, 2, stringH);      //Conversion float humid to string
  radio.write(&stringH, sizeof(stringH)); 
  
  
  delay(1000);

}
  dtostrf(dataTemp,3,2,stringT);          //Conversion float temp to string

In a field width of 3, print the temperature with 2 decimal places. Is your temperature sensor accurate to 0.01 degrees? I've never seen one that is affordable with that level of accuracy. Two decimal places, the dot, and one character before the decimal place requires a field with of at least 4. That requires an array of at least 5 elements. If the temperature is 10 or higher, make that 5 and 6. If the temperature can get to 100 or more, make that 6 and 7.

The extra float variables are pointless.

As temperature is <100C dtostrf(dataTemp,5,6,stringT); as you mentioned. If I want to send the temperature through RF24 is it correct to write it radio.write(&stringT, sizeof(stringT));?

I found exactly the same project as I am building on < Arduino Wireless Temperature LCD Display (nRF24L01+ DHT11) | ELEC-CAFE.COM > I tried to upload the sketch and its not compilable for transmition and reception.

As temperature is <100C
Code: [Select]

dtostrf(dataTemp,5,6,stringT);

How is a two digit whole number, a decimal point, and 6 digits after the decimal point going to fit in 5 characters?

So, now your temperature sensor is accurate to 0.000001 degrees? Quit blowing smoke.

Quit blowing smoke.

Let's fix this. Should be now 00.1 C.

dtostrf(dataTemp,3,1,stringT);

I tried to upload this sketch, but the compiler says "
RF24L01RX.ino: In function 'void loop()':
RF24L01RX:27: error: void value not ignored as it ought to be.

The DHT11 library is on this link:Arduino Wireless Temperature LCD Display (nRF24L01+ DHT11) | ELEC-CAFE.COM

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <DHT11.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

float temperature[2];

RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void) {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.print("Humidity & temp");
delay(1000);
lcd.clear();
lcd.print("Starting.....");
delay(1000);
}

void loop(void)
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read(temperature, sizeof(temperature));
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print("Temp");
lcd.setCursor(0, 1);
lcd.print("Humidity");
lcd.setCursor(9, 0);
lcd.print(temperature[0]);
lcd.print(" C");
lcd.setCursor(9, 1);
lcd.print(temperature[1]);
lcd.print(" %");
delay(1000);
}
}
else
{
lcd.setCursor(0, 0);
lcd.print("No radio available");
}
}