WetterDisplay/include/mess_htu21.h
hans-jurgen 8897226d9a 2024-12-0400
Ich habe Touchscreen oder SD Card einrichten können.
Beides zusammen geht nicht.
Schade !!!!
2024-12-04 22:32:31 +01:00

69 lines
1.9 KiB
C

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_HTU21DF.h>
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
#define I2C_SDA 22
#define I2C_SCL 27
bool F_HTU_21D;
float K_HTU= -0.00;
struct {
char temperature[15] = {0};
char humity[15] = {0};
float t = 0.0;
float h = 0.0;
} htuData;
void init_HTU21(){
Wire.begin(I2C_SDA, I2C_SCL);
F_HTU_21D = false;
if (!htu.begin()) {
Serial.println("Couldn't find sensor HUT21D!");
//SystemStatus = SystemStatus | HTU21noReady;
}else{
F_HTU_21D = true;
Serial.println("HUT21D gefunden");
}
}
void read_HTU21D() {
htuData.t = htu.readTemperature();
//htuData.t = htuData.t + KorrekturTemperaturHTU;
dtostrf(htuData.t,7,1,htuData.temperature);
htuData.h = htu.readHumidity();
dtostrf(htuData.h,7,1,htuData.humity);
Serial.print("Temperature (HTU21D):\t");
Serial.print(htuData.temperature);
Serial.print(" °C\t");
tft.drawString("Temperatur: ", 1, x, 4);
tft.drawFloat(htuData.t, 1.0,190, x,4);
tft.drawString("o", 252, x, 1);
tft.drawString("C", 260, x, 4);
Serial.println(htuData.t,8);
Serial.print("Luftfeuchtigkeit:\t");
Serial.print(htuData.humity);
Serial.println(" %");
tft.drawString("Luftfeuchtigkeit: ", 1, x +=25, 4);
tft.drawFloat(htuData.h, 1.0,190, x, 4);
tft.drawString("%", 252, x, 4);
x = 100;
}
void M2M_HTU21D(String deviceId = "4711") {
/* char topic[100];
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_Htu_21" );
client.publish(topic, htuData.temperature, true);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/humity" );
client.publish(topic, htuData.humity, true); */
/* Serial.printf("HTU21:\t\t %s °C\n", htuData.temperature);
Serial.printf("HTU21:\t\t %s %%\n", htuData.humity); */
}