this is the AHT20 libraries example code i modified to print to a 16,2 i2c lcd, it prints to the serial monitor no problem but on the lcd it prints the first number replaces the second with a period then prints the rest as normal ex. temp = 24.56C / humidity = 45.87% lcd prints "2.56C 4.87%" couldnt find much online
#include <Wire.h>
#include <AHT20.h>
#include <LiquidCrystal_I2C.h>
AHT20 aht20;
LiquidCrystal_I2C lcd (0x27,16,2);
void setup()
{
Serial.begin(115200);
Serial.println("Humidity AHT20 examples");
Wire.begin(); //Join I2C bus
//Check if the AHT20 will acknowledge
if (aht20.begin() == false)
{
Serial.println("AHT20 not detected. Please check wiring. Freezing.");
while (1);
}
Serial.println("AHT20 acknowledged.");
lcd.begin();
lcd.backlight();
lcd.setBacklight (HIGH);
}
void loop()
{
//If a new measurement is available
if (aht20.available() == true)
{
//Get the new temperature and humidity value
float temp = aht20.getTemperature(); // temp = temerature0
float hum = aht20.getHumidity(); // hum = humidity
//Print the results
Serial.print("Temperature: ");
Serial.print(temp, 2);
Serial.print(" C\t");
Serial.print("Humidity: ");
Serial.print(hum, 2);
Serial.print("% RH");
Serial.println();
lcd.setCursor (0,0);
lcd.print (temp);
lcd.print("C");
// humidity beside temp
lcd.setCursor (8,0);
lcd.print (hum);
//lcd.setCursor (11,0);
lcd.print ("%");
delay (1000);
}
//The AHT20 can respond with a reading every ~50ms. However, increased read time can cause the IC to heat around 1.0C above ambient.
//The datasheet recommends reading every 2 seconds.
delay(2000);
}
When printing to an LCD, I follow this format:
example only
lcd.setCursor(0, 0);
// 111111
// 0123456789012345
lcd.print("Temperatura "); //show temperature on LCD
lcd.setCursor(12, 0);
// 111111
// 0123456789012345
// Temperatura xx'C
lcd.print(temp); //append the actual value
lcd.print((char)223);
lcd.print("C");
Using the number above as an example the LCD will take the ones place and turn it into a period, changing the temp from 25.75°C to 2.75°C same with the humidity, the serial monitor, however, will print 25.75. Im just confused because they should print the same data using the same print (temp); and (hum); which is the data from the sensor