problem LCD (DHT33 Virtualwire)

Hello everyone,

I am an avid electronics but starting in Arduino, I trained several tutorial and exercises, I decided to go a step up and try a wireless transmission (helping me more examples on the net;)) between DHT33 (via mini arduino) and a 16x2 LCD display (via an arduino MEGA), I use a transmitter and receiver 433Mhz.

communication is established between my arduino ! and my values sent by the DHT are well converted and displayed on the Serial Monitor.

My problem is that nothing appears on my LCD :frowning:

I made a lcdprint in void setup with a message to test, and it works! but not to show my values !!

therefore i need help to understand what's wrong.

here is the code for the transmitter:

#include <VirtualWire.h>
#include <VirtualWire_Config.h>
#include <dht.h>
#define DHT33_PIN 6

dht DHT;
int T;
int H;
char data[21];

void setup() {
  
  pinMode(13,OUTPUT);
  vw_setup(2000);
  vw_set_tx_pin(2);
  }
  
  void loop() {
    
    digitalWrite(13,HIGH);
    
    uint32_t start = micros();
    int chk = DHT.read33(DHT33_PIN);
    uint32_t stop = micros();
    
     H = DHT.humidity * 100;
     T = DHT.temperature * 100;
     
     sprintf(data, "%d,%d", T, H);
     
     vw_send((uint8_t *)data, strlen(data));
     vw_wait_tx();  
    
    digitalWrite(13,LOW);
    delay(1000);
  
 }

the reciver:

#include <LiquidCrystal.h>
#include <VirtualWire.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char data[21];
int t;
int h;
float T;
float H;


void setup() {
  
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(13,OUTPUT);
  
  vw_setup(2000);
  vw_set_rx_pin(6);  
  vw_rx_start();  
}

  void loop() {
    memset( data, 0, sizeof( data ));
    
    
    Serial.println(t);
    Serial.println(h);
    Serial.println(T);
    Serial.println(H);
    
    digitalWrite(13, HIGH);
    
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    if (vw_get_message(buf, &buflen)) 
    {
 int i;
        for (i = 0; i < buflen; i++)
 {            
         data[i] = char(buf[i]);
 }
  
      sscanf(data, "%d,%d",&t, &h);
      T = t;
      T = T/100;
      H = h;
      H = H/100;
          
      digitalWrite(13,LOW);   
         
    }
  affichage();

}


void affichage() {
    lcd.clear() ;
    lcd.setCursor(0, 0);
    lcd.print("DHT SANS FIL");
    lcd.setCursor(0, 1);
    lcd.print("T ");
    lcd.setCursor(2, 1);
    lcd.print(T);
    lcd.setCursor(8, 1);
    lcd.print("H ");
    lcd.setCursor(10, 1);
    lcd.print(H);
    lcd.setCursor(15, 1);
    lcd.print("%");
    }

affichage() is called every pass through the loop, and with the lcd.clear() at the start of the function the display is not being written to long enough to view. I would put affichage() and the Serial.print() statements in the section where you receive new data. I would also put all the unchanging parts of the display in setup. Instead of using lcd.clear(), which is relatively slow, manage the cursor position in affichage() and print blank spaces to clear where the changing numbers go.

#include <LiquidCrystal.h>
#include <VirtualWire.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char data[21];
int t;
int h;
float T;
float H;

void setup() {

  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("DHT SANS FIL");
  lcd.setCursor(0, 1);
  lcd.print("T ");
  lcd.setCursor(8, 1);
  lcd.print("H ");
  lcd.setCursor(15, 1);
  lcd.print("%");

  pinMode(13, OUTPUT);

  vw_setup(2000);
  vw_set_rx_pin(6);
  vw_rx_start();
}

void loop() {
  memset( data, 0, sizeof( data ));


  //Serial.println(t);
  //Serial.println(h);
  //Serial.println(T);
  //Serial.println(H);

  digitalWrite(13, HIGH);

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen))
  {
    int i;
    for (i = 0; i < buflen; i++)
    {
      data[i] = char(buf[i]);
    }

    sscanf(data, "%d,%d", &t, &h);
    T = t;
    T = T / 100;
    H = h;
    H = H / 100;

    digitalWrite(13, LOW);
    
    affichage();

    Serial.println(t);
    Serial.println(h);
    Serial.println(T);
    Serial.println(H);
  }

  //affichage();

}


void affichage() {
  //lcd.clear() ;
  //lcd.setCursor(0, 0);
  //lcd.print("DHT SANS FIL");
  //lcd.setCursor(0, 1);
  //lcd.print("T ");
  lcd.setCursor(2, 1);
  lcd.print("      "); //six spaces
  lcd.setCursor(2, 1);
  lcd.print(T);
  //lcd.setCursor(8, 1);
  //lcd.print("H ");
  lcd.setCursor(10, 1);
  lcd.print("     "); //five spaces
  lcd.setCursor(10, 1);
  lcd.print(H);
  //lcd.setCursor(15, 1);
  //lcd.print("%");
}

thank you for your reply !

I tested the code, but it does not work!

Now the letter U is displayed on all LCD

it's really strange

I edit the code and here is the latest upgraded version
it shows me the text I put in void setup but T and H are not displayed
in the Serial Monitor I have my values displayed

#include <LiquidCrystal.h>
#include <VirtualWire.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char data[21];
int t;
int h;
float T;
float H;


void setup() {
  
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("DHT SANS FIL");
  lcd.setCursor(0, 1);
  lcd.print("T ");
  lcd.setCursor(8, 1);
  lcd.print("H ");
  lcd.setCursor(15, 1);
  lcd.print("%");
  
  vw_setup(2000);
  vw_set_rx_pin(6);  
  vw_rx_start();  
}

  void loop() {
    
    memset( data, 0, sizeof( data ));
    
    digitalWrite(13, HIGH);
    
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    if (vw_get_message(buf, &buflen)) 
    {
 int i;
        for (i = 0; i < buflen; i++)
 {            
         data[i] = char(buf[i]);
 }
  
      sscanf(data, "%d,%d",&t, &h);
      T = t;
      T = T/100;
      H = h;
      H = H/100;
          
      digitalWrite(13,LOW);   
         
    }
  affichage();

}


void affichage() {
    
    Serial.println(t);
    Serial.println(h);
    Serial.println(T);
    Serial.println(H);
    
           
    lcd.setCursor(2, 1);
    lcd.print(T,1);
    
    lcd.setCursor(10, 1);
    lcd.print(H);
    
    delay(1000);
    
    }

Take a closer look at your brackets and where the call of affichage() is located. The display function needs to be within the brackets which define the if (vw_get_message(buf, &buflen)) block. The call to affichage() needs to go up one bracket, and be next to the digitalWrite(13,LOW); without a bracket in between them. You should be able to remove the delay(1000) from affichage().

I found where have the problem!
there is a problem with the virtualwire, I replaced it with the library radiohead and It Works!
I put the code that works:

transmitter:

#include <RH_ASK.h>
#include <SPI.h>
#include <dht.h>
#define DHT33_PIN 6

RH_ASK driver(2000,6,2);

dht DHT;
int T;
int H;
char data[21];

void setup() {
  
  pinMode(13,OUTPUT);
  if (!driver.init())
         Serial.println("init failed");
  }
  
  void loop() {
    
    digitalWrite(13,HIGH);
    
    uint32_t start = micros();
    int chk = DHT.read33(DHT33_PIN);
    uint32_t stop = micros();
    
     H = DHT.humidity * 100;
     T = DHT.temperature * 100;
     
     sprintf(data, "%d,%d", T, H);
     
     driver.send((uint8_t *)data, strlen(data));
    driver.waitPacketSent();
      
    
    digitalWrite(13,LOW);
    delay(500);
  
 }

reception:

#include <RH_ASK.h>
#include <SPI.h>

#include <LiquidCrystal.h>

RH_ASK driver(2000,6);


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char data[21];
int t;
int h;
float T;
float H;


void setup() {
  
  //Serial.begin(9600);
  pinMode(13,OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("DHT SANS FIL");
  lcd.setCursor(0, 1);
  lcd.print("T ");
  lcd.setCursor(8, 1);
  lcd.print("H ");
  lcd.setCursor(15, 1);
  lcd.print("%");
  
  if (!driver.init())
         Serial.println("init failed");
}

  void loop() {
    
    memset( data, 0, sizeof( data ));
    
    digitalWrite(13, HIGH);
    
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);

    
    if (driver.recv(buf, &buflen)) 
    {
 int i;
        for (i = 0; i < buflen; i++)
 {            
         data[i] = char(buf[i]);
 }
  
      sscanf(data, "%d,%d",&t, &h);
      T = t;
      T = T/100;
      H = h;
      H = H/100;
          
      digitalWrite(13,LOW); 
    affichage();  
         
    }
  

}


void affichage() {
    
    Serial.println(t);
    Serial.println(h);
    Serial.println(T);
    Serial.println(H);
    
           
    lcd.setCursor(2, 1);
    lcd.print(T);
    
    lcd.setCursor(10, 1);
    lcd.print(H);
   
    
    }

thank you all for your help