Temperatur auf Display ausgeben läuft - fast
Hallo Leute,
Ich benutze ein HX8357C 3" Display am Arduino Mega 2560, das mir 2 Temperaturen über Dallas 18B20 anzeigen soll.
Als absoluter Noob in C, hab ich zum laufen gebracht:
1); aus beiden 18B20 Temperatur auslesen funktioniert
2); die Anzeige zu formatieren funktioniert auch. Aller Code dazu steht im void setup (//runs once!) , so das eine saubere Anzeige da ist.
im void loop (// runs forever!) schreibe ich die zwei Temperaturen ins Display. - funktioniert ; Temperaturänderungen werden übernommen.
3); my flaw in the plan: Jede neue Messung überschreibt die alte Anzeige, aber ohne sie zu löschen. Bei 5 Messungen liegen 5 Werte übereinander.
Wie lösche ich den alten Wert aus dem Display, wenn der neue geschrieben wird?
Code:
/*
Test the tft.print() viz the libraries embedded write() function
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_ILI9341 library folder.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
changed by dh4mbm 2016.11.06 uses Dallas DS18B20 temperature sensor
* partial Working Sketch * 480 x 320 Display is working * refreshes Temp, overides Temp in display, without deleting previous drawn digits*
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 2
#define ONE_WIRE_BUS_2 4
OneWire oneWire_in(ONE_WIRE_BUS_1);
OneWire oneWire_out(ONE_WIRE_BUS_2);
DallasTemperature sensor_inhouse(&oneWire_in);
DallasTemperature sensor_outhouse(&oneWire_out);
#include <TFT_HX8357.h> // Hardware-specific library
byte fontSize4 = 4; // 26 px, FontSize 4, 6, 7, 8
byte fontSize6 = 6; // 48 px
TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library
int timer1 = (3000);
void setup(void) {
tft.init();
tft.setRotation(1);
sensor_inhouse.begin();
sensor_outhouse.begin();
// delay(timer1);
/* Fill screen with colour so we can see the effect of printing with and without
code color
*/
tft.fillScreen(TFT_YELLOW); // TFT_YELLOW = Blue - TFT_BLUE = YELLOW
tft.setTextColor(TFT_BLUE); // TFT_WHITE = Black - TFT_BLUE = White << Das muß raus, dann gehts!
tft.setCursor(40, 48, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setTextFont(fontSize4);
tft.println("Dallas TwoPin_DS18B20");
// Set "cursor" at top left corner of display (0,0) and select font 4
// (cursor will move to next line automatically during printing with 'tft.println'
// or stay on the line is there is room for the text with tft.print)
tft.setCursor(40, 172, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Inhouse: ");
tft.setCursor(380, 172, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Degree ");
tft.setCursor(40, 248, fontSize4);
tft.print("Outhouse: ");
tft.setCursor(380, 248, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Degree ");
}
void loop() {
tft.setCursor(40, 98, fontSize4); // Spalte, Zeile, Font
tft.println("Requesting temperatures...");
sensor_inhouse.requestTemperatures();
sensor_outhouse.requestTemperatures();
tft.setCursor(190, 172, fontSize6); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print(sensor_inhouse.getTempCByIndex(0)); //writes temperature from pin 2
tft.setCursor(190, 248, fontSize6);
tft.print(sensor_outhouse.getTempCByIndex(0)); //writes temperature from pin 4
}
Solved: Temperatur auf Display ausgeben läuft!
Problem solved!
Herzlichen Dank für eure Hilfe.
Aus dem setup() habe ich die Befehlszeile :
tft.setTextColor(TFT_BLUE); // TFT_WHITE = Black - TFT_BLUE = White
entfernt. Das hat die Farben durcheinander gewürfelt. Weißer Hintergrund mit schwarzer Schrift funktioniert.
Ich nutze dieses Display: https://eckstein-shop.de/Mega-2560-3...d-fuer-Arduino
Es liest zwei Dallas-DS18B20 Temperatursensoren aus. http://playground.arduino.cc/Learning/OneWire
Auf beiden Seiten findet ihr die zugehörige library.
Hier nun der funktionierende Code:
Code:
/*
Test the tft.print() viz the libraries embedded write() function
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_ILI9341 library folder.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
changed by dh4mbm 2016.11.06 uses Dallas DS18B20 temperature sensor and MEGA 2560
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 2 // use Arduino Pin 2
#define ONE_WIRE_BUS_2 4 // use Arduino Pin 4
OneWire oneWire_in(ONE_WIRE_BUS_1);
OneWire oneWire_out(ONE_WIRE_BUS_2);
DallasTemperature sensor_inhouse(&oneWire_in);
DallasTemperature sensor_outhouse(&oneWire_out);
#include <TFT_HX8357.h> // Hardware-specific library
byte fontSize4 = 4; // 26 px, FontSize 4, 6, 7, 8
byte fontSize6 = 6; // 48 px
TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library
int timer1 = (3000);
void setup(void) {
tft.init();
tft.setRotation(1);
sensor_inhouse.begin();
sensor_outhouse.begin();
/* Fill screen with colour so we can see the effect of printing with and without
code color
*/
tft.fillScreen(TFT_BLACK); // TFT_YELLOW = Blue - TFT_BLUE = YELLOW - TFT_BLACK = White
tft.setCursor(40, 48, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setTextFont(fontSize4);
tft.println("Dallas TwoPin_DS18B20");
// (cursor will move to next line automatically during printing with 'tft.println'
// or stay on the line is there is room for the text with tft.print)
tft.setCursor(40, 172, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Inhouse: ");
tft.setCursor(380, 172, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Degree ");
tft.setCursor(40, 248, fontSize4);
tft.print("Outhouse: ");
tft.setCursor(380, 248, fontSize4); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.print("Degree ");
}
void loop() {
tft.setCursor(40, 98, fontSize4); // Spalte, Zeile, Font
tft.println("Requesting temperatures...");
sensor_inhouse.requestTemperatures();
sensor_outhouse.requestTemperatures();
tft.setCursor(190, 172, fontSize6); //shift Cursor in Pixel (Collum, Row, Fontsize)
tft.setCursor(190, 172, fontSize6);
tft.print(sensor_inhouse.getTempCByIndex(0));
tft.setCursor(190, 172, fontSize6);
tft.setCursor(190, 248, fontSize6);
tft.print(sensor_outhouse.getTempCByIndex(0));
}