2024-10-1502
This commit is contained in:
parent
2deb92ffe8
commit
4a3976e1ca
|
@ -19,8 +19,7 @@ lib_deps =
|
||||||
bodmer/TFT_eSPI @ 2.5.43
|
bodmer/TFT_eSPI @ 2.5.43
|
||||||
paulstoffregen/XPT2046_Touchscreen @ 0.0.0-alpha+sha.26b691b2c8
|
paulstoffregen/XPT2046_Touchscreen @ 0.0.0-alpha+sha.26b691b2c8
|
||||||
adafruit/Adafruit Unified Sensor @ 1.1.14
|
adafruit/Adafruit Unified Sensor @ 1.1.14
|
||||||
#adafruit/Adafruit HTU21DF Library @ 1.0.5
|
adafruit/DHT sensor library @ 1.4.6
|
||||||
milesburton/DallasTemperature @ 3.11.0
|
|
||||||
|
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DKorrekturTemperatur=0.0
|
-DKorrekturTemperatur=0.0
|
||||||
|
|
75
src/main.cpp
75
src/main.cpp
|
@ -27,6 +27,11 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||||
|
|
||||||
#define TFT_GREY 0x5AEB
|
#define TFT_GREY 0x5AEB
|
||||||
|
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <DHT_U.h>
|
||||||
|
#define DHTPIN 22
|
||||||
|
#define DHTTYPE DHT22
|
||||||
|
|
||||||
float ltx = 0; // Saved x coord of bottom of needle
|
float ltx = 0; // Saved x coord of bottom of needle
|
||||||
uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords
|
uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords
|
||||||
|
@ -38,6 +43,10 @@ int value[6] = {0, 0, 0, 0, 0, 0};
|
||||||
int old_value[6] = { -1, -1, -1, -1, -1, -1};
|
int old_value[6] = { -1, -1, -1, -1, -1, -1};
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
|
DHT_Unified dht(DHTPIN, DHTTYPE);
|
||||||
|
|
||||||
|
uint32_t delayMS;
|
||||||
|
|
||||||
void analogMeter();
|
void analogMeter();
|
||||||
void plotNeedle(int value, byte ms_delay);
|
void plotNeedle(int value, byte ms_delay);
|
||||||
|
|
||||||
|
@ -46,17 +55,36 @@ void setup(void) {
|
||||||
tft.init();
|
tft.init();
|
||||||
tft.setRotation(1);
|
tft.setRotation(1);
|
||||||
Serial.begin(115200); // For debug
|
Serial.begin(115200); // For debug
|
||||||
|
dht.begin();
|
||||||
|
Serial.println(F("DHTxx Unified Sensor Example"));
|
||||||
|
// Print temperature sensor details.
|
||||||
|
sensor_t sensor;
|
||||||
|
dht.temperature().getSensor(&sensor);
|
||||||
|
/* Serial.println(F("------------------------------------"));
|
||||||
|
Serial.println(F("Temperature Sensor"));
|
||||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
|
||||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
|
||||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
|
||||||
|
Serial.println(F("------------------------------------")); */
|
||||||
|
// Print humidity sensor details.
|
||||||
|
dht.humidity().getSensor(&sensor);
|
||||||
|
/* Serial.println(F("Humidity Sensor"));
|
||||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
|
||||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
|
||||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
|
||||||
|
Serial.println(F("------------------------------------")); */
|
||||||
|
// Set delay between sensor readings based on sensor details.
|
||||||
|
delayMS = sensor.min_delay / 1000;
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
tft.drawString("Raumfeuchtigkeit", 1, 210, 4);
|
tft.drawString("Raumfeuchtigkeit", 1, 210, 4);
|
||||||
//I2C_2.begin(SDA_2, SCL_2, I2C_FREQ);
|
|
||||||
//delay(9000);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//delay(10000);
|
|
||||||
|
|
||||||
analogMeter(); // Draw analogue meter
|
analogMeter(); // Draw analogue meter
|
||||||
|
|
||||||
updateTime = millis(); // Next update time
|
updateTime = millis(); // Next update time
|
||||||
|
@ -69,13 +97,36 @@ void setup(void) {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
float Temperatur;
|
float Temperatur;
|
||||||
|
delay(delayMS);
|
||||||
|
// Get temperature event and print its value.
|
||||||
|
sensors_event_t event;
|
||||||
|
dht.temperature().getEvent(&event);
|
||||||
|
if (isnan(event.temperature)) {
|
||||||
|
Serial.println(F("Error reading temperature!"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print(F("Temperature: "));
|
||||||
|
Temperatur = event.temperature;
|
||||||
|
Serial.print(Temperatur);
|
||||||
|
Serial.println(F("°C"));
|
||||||
|
}
|
||||||
|
// Get humidity event and print its value.
|
||||||
|
dht.humidity().getEvent(&event);
|
||||||
|
if (isnan(event.relative_humidity)) {
|
||||||
|
Serial.println(F("Error reading humidity!"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print(F("Humidity: "));
|
||||||
|
Serial.print(event.relative_humidity);
|
||||||
|
Serial.println(F("%"));
|
||||||
|
}
|
||||||
if (updateTime <= millis()) {
|
if (updateTime <= millis()) {
|
||||||
updateTime = millis() + 5000; // Update meter every 35 milliseconds
|
updateTime = millis() + 5000; // Update meter every 35 milliseconds
|
||||||
|
|
||||||
// Create a Sine wave for testing
|
// Create a Sine wave for testing
|
||||||
d += 4; if (d >= 360) d = 0;
|
d += 4; if (d >= 360) d = 0;
|
||||||
value[0] = 50 + 50 * sin((d + 0) * 0.0174532925);
|
//value[0] = 50 + 50 * sin((d + 0) * 0.0174532925);
|
||||||
|
value[0] = event.relative_humidity;
|
||||||
|
|
||||||
plotNeedle(value[0], 0); // It takes between 2 and 12ms to replot the needle with zero delay
|
plotNeedle(value[0], 0); // It takes between 2 and 12ms to replot the needle with zero delay
|
||||||
tft.fillRect(0, 179, 310, 60, TFT_GREEN);
|
tft.fillRect(0, 179, 310, 60, TFT_GREEN);
|
||||||
|
@ -86,7 +137,7 @@ void loop() {
|
||||||
tft.drawString("o", 212, 180, 1);
|
tft.drawString("o", 212, 180, 1);
|
||||||
tft.drawString("C", 220, 180, 4);
|
tft.drawString("C", 220, 180, 4);
|
||||||
tft.drawString("Raumfeuchtigkeit:", 1, 210, 4);
|
tft.drawString("Raumfeuchtigkeit:", 1, 210, 4);
|
||||||
char buf[8]; dtostrf(value[0], 3, 0, buf);
|
char buf[8]; dtostrf(event.relative_humidity, 3, 0, buf);
|
||||||
tft.drawString(buf, 230, 210, 4);
|
tft.drawString(buf, 230, 210, 4);
|
||||||
tft.drawString("%", 270, 210, 4);
|
tft.drawString("%", 270, 210, 4);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +238,7 @@ void analogMeter()
|
||||||
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
tft.drawString("%", M_SIZE*(5 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
|
//tft.drawString("%", M_SIZE*(5 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
|
||||||
tft.drawCentreString("%", M_SIZE*120, M_SIZE*70, 4); // Comment out to avoid font 4
|
tft.drawCentreString("%", M_SIZE*120, M_SIZE*70, 4); // Comment out to avoid font 4
|
||||||
tft.drawRect(5, 3, M_SIZE*230, M_SIZE*119, TFT_BLACK); // Draw bezel line
|
tft.drawRect(5, 3, M_SIZE*230, M_SIZE*119, TFT_BLACK); // Draw bezel line
|
||||||
|
|
||||||
|
@ -205,7 +256,7 @@ void plotNeedle(int value, byte ms_delay)
|
||||||
{
|
{
|
||||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||||
char buf[8]; dtostrf(value, 4, 0, buf);
|
char buf[8]; dtostrf(value, 4, 0, buf);
|
||||||
tft.drawRightString(buf, M_SIZE*40, M_SIZE*(119 - 20), 2);
|
//tft.drawRightString(buf, M_SIZE*40, M_SIZE*(119 - 20), 2);
|
||||||
|
|
||||||
if (value < -10) value = -10; // Limit value to emulate needle end stops
|
if (value < -10) value = -10; // Limit value to emulate needle end stops
|
||||||
if (value > 110) value = 110;
|
if (value > 110) value = 110;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user