tft.fillScreen(0);
Leert den Bildschirm?!
War die Absicht dahinter.
Du kannst auch an Stelle der 0 BLACK reinschreiben.
Siehe weiter oben bei der Variablendefinition.
die 0 war nur schneller....
ok, habe mir gedacht.
Die Tempanzeige funktioniert.
Ich habe das :
tft.fillScreen(BLACK); mit
tft.setTextColor(WHITE,BLACK); ersetzt
damit erreiche ich wider, dass der rest des Text erhalten bleibt und nicht gelöscht wird.
Und das Celsius Zeichen gebe ich momentan mit ((char)260) aus.
Die 176 und 0B.. shen sschlecht aus
Beachte: Wenn die Temperatur nicht die selbe anzahl digits hat, kommt es zu Anzeigefehlern!
Wenn temperatur[0] vorher 10,00 °C war und danach 9,99°C, dann steht auf der Anzeige: 9,99°CC!
Das muss vorher gelöst werden.
Am günstigsten ist, den bisherigen Wert erst mit dem selben Inhalt zu überschreiben und dabei die selbe Vorder- und Hintergrundfarbe zu verwenden.
dann den Vordergrund neu setzen, die Position neu setzen und den neuen Wert schreiben.
Funktioniert so..
Temp auf über 100c und wider runter bis 5c.. keine probleme
Nein.
Das funktioniert nur, weil Du hinten raus Leerzeichen anfügst.
Spätestens dann, wenn Du mal irgendwas hast, was dahinter noch steht, kommst Du in Schwulitäten.
Mein Vorschlag:
#include <MCUFRIEND_kbv.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
constexpr byte ONE_WIRE_BUS {40};
constexpr byte LCD_RESET {A4}; // Can alternately just connect to Arduino's reset pin
constexpr byte LCD_CS {A3}; // Chip Select goes to Analog 3
constexpr byte LCD_CD {A2}; // Command/Data goes to Analog 2
constexpr byte LCD_WR {A1}; // LCD Write goes to Analog 1
constexpr byte LCD_RD {A0}; // LCD Read goes to Analog 0
constexpr uint16_t BLACK {0x0000};
constexpr uint16_t BLUE {0x001F};
constexpr uint16_t RED {0xF800};
constexpr uint16_t GREEN {0x07E0};
constexpr uint16_t CYAN {0x07FF};
constexpr uint16_t MAGENTA {0xF81F};
constexpr uint16_t YELLOW {0xFFE0};
constexpr uint16_t WHITE {0xFFFF};
MCUFRIEND_kbv tft;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Addresses of 3 DS18B20s
constexpr byte sensorNums {2};
constexpr uint8_t sensor[sensorNums][8] =
{
{ 0x28, 0xE2, 0x9E, 0x83, 0xB1, 0x22, 0x08, 0x98 },
{ 0x28, 0x91, 0x56, 0x62, 0xB1, 0x22, 0x08, 0x83 }
};
float temperatur[sensorNums];
constexpr uint32_t intervall {1000};
uint32_t lastRequest;
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Start..."));
tft.begin();
tft.setRotation(1);
sensors.begin();
tft.fillScreen(BLACK); // TFT_YELLOW = Blue - TFT_BLUE = YELLOW - TFT_BLACK = White
tft.setCursor(10, 20); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setTextSize(2);
tft.println("Dallas TwoPin_DS18B20");
tft.setCursor(20, 50); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Inhouse: ");
tft.setCursor(20, 75); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setCursor(20, 100);
tft.print("Outhouse: ");
tft.setCursor(20, 120); //shift Cursor in Pixel (Collum, Row, Fontsize)
}
void loop(void)
{
if (millis() - lastRequest > intervall)
{
lastRequest = millis();
printTemperature();
sensors.requestTemperatures();
}
}
//
void printTemperature()
{
fillScale(BLACK, BLACK);
for (byte b = 0; b < sensorNums; b++)
{ temperatur[b] = sensors.getTempC(sensor[b]); }
fillScale(BLACK, WHITE);
}
void fillScale(const uint16_t fg, const uint16_t bg)
{
tft.setTextColor(fg, bg);
tft.setCursor(150, 50);
tft.print(temperatur[0]);
tft.print((char)176);
tft.print('C');
tft.setCursor(150, 100);
tft.print(temperatur[1]);
tft.print((char)176);
tft.print('C');
}
Was willste damit machen?
Zwei mall hintereinander tft.setCursor der letzter wird doch genommen.
Gut ist im Setup trotz dem.
Falsche Adresse.
Ich hab nur zwei Sensoren ausgelesen und zur Anzeige gebracht
Hast ja alles umgebaut
Hey, danke, ich hab den mal genommen.
Ich habe dazu einen DHT22 dazu genommen, funktioniert so weit.
Nur: der DHT wird im Display direkt aktualisiert, ohne dass das das ganze tft neu geladen wird.
Die 2 DS18B20 Temperaturen werden über den "constexpr uint32_t intervall {5000};" akualisiert, und jedes mal lädt das tft die neuen Daten.
Wie kann ich das für die Ds18b20 machen?
#include <MCUFRIEND_kbv.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
// Data wire is plugged into port 2 on the Arduino
constexpr byte ONE_WIRE_BUS {40};
constexpr byte LCD_RESET {A4}; // Can alternately just connect to Arduino's reset pin
constexpr byte LCD_CS {A3}; // Chip Select goes to Analog 3
constexpr byte LCD_CD {A2}; // Command/Data goes to Analog 2
constexpr byte LCD_WR {A1}; // LCD Write goes to Analog 1
constexpr byte LCD_RD {A0}; // LCD Read goes to Analog 0
constexpr uint16_t BLACK {0x0000};
constexpr uint16_t BLUE {0x001F};
constexpr uint16_t RED {0xF800};
constexpr uint16_t GREEN {0x07E0};
constexpr uint16_t CYAN {0x07FF};
constexpr uint16_t MAGENTA {0xF81F};
constexpr uint16_t YELLOW {0xFFE0};
constexpr uint16_t WHITE {0xFFFF};
MCUFRIEND_kbv tft;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
#define DHTPIN 30
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//#define DHTPIN {40}
// Addresses of 3 DS18B20s
constexpr byte sensorNums {2};
constexpr uint8_t sensor[sensorNums][8] =
{
{ 0x28, 0xE2, 0x9E, 0x83, 0xB1, 0x22, 0x08, 0x98 },
{ 0x28, 0x91, 0x56, 0x62, 0xB1, 0x22, 0x08, 0x83 }
};
float temperatur[sensorNums];
float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit“ speichern
float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur“ speichern
constexpr uint32_t intervall {5000};
uint32_t lastRequest;
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Start..."));
tft.begin();
tft.setRotation(1);
sensors.begin();
dht.begin();
tft.fillScreen(BLACK); // TFT_YELLOW = Blue - TFT_BLUE = YELLOW - TFT_BLACK = White
tft.setCursor(10, 20); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setTextSize(2);
tft.println("Dallas TwoPin_DS18B20");
tft.setCursor(20, 50); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Inhouse: ");
tft.setCursor(265, 50);
tft.print((char)"\367");
tft.print("C");
//shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setCursor(20, 100);
tft.print("Outhouse: ");
tft.setCursor(265, 100);
tft.print((char)"\367");
tft.print("C");
tft.setCursor(20, 140); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Temperatur: ");
tft.setCursor(265, 140);
tft.println("C");
tft.setTextSize(1,2);
tft.setCursor(20, 170);
tft.print("Luftfeuchtigkeit: ");
tft.setCursor(265, 170);
tft.println("%");
}
void loop(void)
{
float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit“ speichern
float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur“ speichern
if (millis() - lastRequest > intervall)
{
lastRequest = millis();
printTemperature();
sensors.requestTemperatures();
}
tft.setTextSize(2);
tft.setCursor(175, 170);
tft.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
tft.setCursor(175, 140);
tft.print(Temperatur);
fillScale(WHITE,BLACK);
}
//
void printTemperature()
{
fillScale(BLACK, BLACK);
for (byte b = 0; b < sensorNums; b++)
{ temperatur[b] = sensors.getTempC(sensor[b]); }
}
void fillScale(const uint16_t fg, const uint16_t bg)
{
tft.setTextColor(fg, bg);
tft.setCursor(175, 50);
tft.print(temperatur[0]);
tft.setCursor(175, 100);
tft.print(temperatur[1]);
}
Hier ein Kurzes Video wo du es siehst.
Persönlich wurde ich bei so einer flackerei Krise bekommen
@fony
Und was kann ich dagegen tun?
Muss mall morgen gucken ob noch 2 DS18xxx habe, 2,4" TFT habe nicht ist aber nicht das Problem. Was für ein Arduino nutzt du ist das ein Mega 2560?
@fony
ok, gerne..
es ist ein elegoo mega r3
Display
https://www.amazon.de/dp/B07YKN1C2Z?psc=1&ref=ppx_yo2ov_dt_b_product_details
Board
https://www.amazon.de/dp/B01MA5BLQI?psc=1&ref=ppx_yo2ov_dt_b_product_details
Versuch das, KBV arbeitet hier mit Adafruit GFX also um das Schmieren beseitigen durfte reichen tft.setTextColor(WHITE,BLACK);
Der DHT sollte sauber laufen aber noch ohne Garantie
#include <MCUFRIEND_kbv.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
// Data wire is plugged into port 2 on the Arduino
constexpr byte ONE_WIRE_BUS {40};
constexpr byte LCD_RESET {A4}; // Can alternately just connect to Arduino's reset pin
constexpr byte LCD_CS {A3}; // Chip Select goes to Analog 3
constexpr byte LCD_CD {A2}; // Command/Data goes to Analog 2
constexpr byte LCD_WR {A1}; // LCD Write goes to Analog 1
constexpr byte LCD_RD {A0}; // LCD Read goes to Analog 0
constexpr uint16_t BLACK {0x0000};
constexpr uint16_t BLUE {0x001F};
constexpr uint16_t RED {0xF800};
constexpr uint16_t GREEN {0x07E0};
constexpr uint16_t CYAN {0x07FF};
constexpr uint16_t MAGENTA {0xF81F};
constexpr uint16_t YELLOW {0xFFE0};
constexpr uint16_t WHITE {0xFFFF};
MCUFRIEND_kbv tft;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
#define DHTPIN 30
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//#define DHTPIN {40}
// Addresses of 3 DS18B20s
constexpr byte sensorNums {2};
constexpr uint8_t sensor[sensorNums][8] =
{
{ 0x28, 0xE2, 0x9E, 0x83, 0xB1, 0x22, 0x08, 0x98 },
{ 0x28, 0x91, 0x56, 0x62, 0xB1, 0x22, 0x08, 0x83 }
};
float temperatur[sensorNums];
float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit“ speichern
float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur“ speichern
constexpr uint32_t intervall {5000};
uint32_t lastRequest;
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Start..."));
tft.begin();
tft.setRotation(1);
sensors.begin();
dht.begin();
tft.fillScreen(BLACK); // TFT_YELLOW = Blue - TFT_BLUE = YELLOW - TFT_BLACK = White
tft.setCursor(10, 20); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setTextSize(2);
tft.println("Dallas TwoPin_DS18B20");
tft.setCursor(20, 50); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Inhouse: ");
tft.setCursor(265, 50);
tft.print((char)"\367");
tft.print("C");
//shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setCursor(20, 100);
tft.print("Outhouse: ");
tft.setCursor(265, 100);
tft.print((char)"\367");
tft.print("C");
tft.setCursor(20, 140); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Temperatur: ");
tft.setCursor(265, 140);
tft.println("C");
tft.setTextSize(1,2);
tft.setCursor(20, 170);
tft.print("Luftfeuchtigkeit: ");
tft.setCursor(265, 170);
tft.println("%");
}
void loop(void)
{
float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit“ speichern
float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur“ speichern
if (millis() - lastRequest > intervall)
{
lastRequest = millis();
printTemperature();
sensors.requestTemperatures();
}
tft.setTextSize(2);
tft.setTextColor(WHITE,BLACK);
tft.setCursor(175, 170);
tft.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
tft.setCursor(175, 140);
tft.print(Temperatur);
//fillScale(WHITE,BLACK);
}
//
void printTemperature()
{
fillScale(BLACK, BLACK);
for (byte b = 0; b < sensorNums; b++)
{ temperatur[b] = sensors.getTempC(sensor[b]); }
}
void fillScale(const uint16_t fg, const uint16_t bg)
{
tft.setTextColor(fg, bg);
tft.setCursor(175, 50);
tft.print(temperatur[0]);
tft.setCursor(175, 100);
tft.print(temperatur[1]);
}
Der DHT läuft bei mir perfekt..
Die 2 DS18b20 nicht..
jetzt weiter ?
Zu deinem neuen Code:
Dht perfekt..
Ds18 keine anzeige
OK habe vor erst nur das geändert
tft.setTextSize(2);
tft.setTextColor(WHITE,BLACK); /******** Neu****/
tft.setCursor(175, 170);
tft.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
tft.setCursor(175, 140);
tft.print(Temperatur);
//fillScale(WHITE,BLACK); // Alt
also erst mall rausnehmen habe deinen ersten Sketch genommen sehe gerade