2024-10-1103 I2C keine Funktion,

This commit is contained in:
hans-jurgen 2024-10-11 22:01:01 +02:00
parent 12fe90e772
commit 660267f0ad
3 changed files with 68 additions and 7 deletions

41
include/htu21d.h Normal file
View File

@ -0,0 +1,41 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
//#include <Adafruit_I2CDevice.h>
#include <Adafruit_HTU21DF.h>
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
bool F_HTU_21D;
float K_HTU= -0.00;
struct {
char temperature[15] = {0};
char humity[15] = {0};
} htuData;
void init_HTU21(){
F_HTU_21D = false;
if (!htu.begin()) {
Serial.println("Couldn't find sensor HUT21D!");
}else{
F_HTU_21D = true;
Serial.println("HUT21D gefunden");
}
}
void read_HTU21D() {
float t = htu.readTemperature();
t = t + KorrekturTemperatur;
dtostrf(t,7,1,htuData.temperature);
float h = htu.readHumidity();
dtostrf(h,7,1,htuData.humity);
Serial.print("Temperature (HTU21D):\t");
Serial.print(htuData.temperature);
Serial.println(" °C");
Serial.print("Luftfeuchtigkeit:\t");
Serial.print(htuData.humity);
Serial.println(" %");
}

View File

@ -19,3 +19,9 @@ lib_deps =
# The exact version
bodmer/TFT_eSPI @ 2.5.43
paulstoffregen/XPT2046_Touchscreen @ 0.0.0-alpha+sha.26b691b2c8
adafruit/Adafruit Unified Sensor @ 1.1.14
#adafruit/Adafruit HTU21DF Library @ 1.0.5
build_flags = ${env.build_flags}
-DKorrekturTemperatur=0.0

View File

@ -15,6 +15,8 @@
Updated by Bodmer for variable meter size
*/
#define ledGreen 16
// Define meter size as 1 for tft.rotation(0) or 1.3333 for tft.rotation(1)
#define M_SIZE 1.3333
@ -25,6 +27,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x5AEB
float ltx = 0; // Saved x coord of bottom of needle
uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords
uint32_t updateTime = 0; // time for next update
@ -41,14 +44,19 @@ void plotNeedle(int value, byte ms_delay);
void setup(void) {
tft.init();
tft.setRotation(1);
Serial.begin(57600); // For debug
Serial.begin(115200); // For debug
tft.fillScreen(TFT_BLACK);
tft.drawString("Raumfeuchtigkeit", 1, 210, 4);
//I2C_2.begin(SDA_2, SCL_2, I2C_FREQ);
//delay(9000);
analogMeter(); // Draw analogue meter
updateTime = millis(); // Next update time
pinMode(ledGreen, OUTPUT);
analogWrite(ledGreen, 102);
//init_HTU21();
delay(5000);
}
@ -99,23 +107,29 @@ void analogMeter()
int y3 = sy2 * M_SIZE*100 + M_SIZE*140;
// Yellow zone limits
//if (i >= -50 && i < 0) {
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW);
// tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW);
//}
if (i >= -50 && i < 0) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW);
}
// Green zone limits
if (i >= 0 && i < 25) {
if (i >= 0 && i < 15) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN);
}
// Orange zone limits
if (i >= 25 && i < 50) {
if (i >= 15 && i < 25) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE);
}
// Red zone limits
if (i >= 25 && i < 50) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_RED);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_RED);
}
// Short scale tick length
if (i % 25 != 0) tl = 8;