HI everyone!! I wish I get help for display problem on my LCD 4x20. I wrote the program to read Temp. and Humid. floats of my AM2302 sensor made by Asair. Then I want to display the values on the LCD.
I get my title '' Parameters'' on the LCD. I get the print of ''Humidity: '' on my LCD. I get the print of ''Temperature: '' on my LCD.
But the values don't print where supposed exept for ''Humidity: '', I get only one digit (7or 6 or 8...) after Humidity:
For the Serial Monitor, I get the Humidity and temperature printed perfectly. Only on LCD that I get erratic printing of the floats. Any Ideas? Here is the program.
Using Genuine Arduino Uno
#include <DHT_Async.h>
#include "DHT.h"
#include "LCDIC2.h" //POur imprimer sur mon LCD
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LCDIC2 lcd(0x27, 20, 4); // Initialiser l'ecran LCD
void setup() {
Serial.begin(9600);
lcd.begin();
Serial.println(F("DHT22+LCD test!"));
lcd.setCursor(5,0);
lcd.print("Parametres");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)|| isnan(f) ) {
Serial.println(F("Failed to read from DHT sensor!"));
lcd.print("Failed to read from DHT sensor!");
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print( t);
Serial.print(F("°C "));
//Serial.print(f);
//Serial.print(F("°F Heat index: "));
//Serial.print(hic);
//Serial.print(F("°C "));
//Serial.print(hif);
//Serial.println(F("°F"));
//MA PARTIE LCD
lcd.setCursor(0,2);
lcd.print(F("Humidity: "));
lcd.setCursor(9,2);
lcd.print(h);
lcd.setCursor(15,2);
lcd.print("%");
lcd.setCursor(0,3);
lcd.print(F("Temperature: "));
lcd.setCursor(12,3);
lcd.print(t);
lcd.setCursor(17,3);
lcd.print(F("C "));
}