PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Temperatur auf Display ausgeben läuft - fast



DH4MBM
09.11.2016, 00:57
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?





/*
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

}

021aet04
09.11.2016, 08:22
Ich kenne das LCD nicht, aber notfalls kannst du die Zeichen zuerst mit einem Leerzeichen überschreiben und anschließend mit dem neuen Zeichen. Habe mir das DB nicht genau durchgelesen, aber ich habe etwas von SW-Reset gelesen. Vielleicht passt das. Ein Kommando wie Display löschen habe ich nicht gefunden.

MfG Hannes

wkrug
09.11.2016, 15:02
Das ist bei den LCD's oft so.
Ich schreib die aktuellen Zeichen in einen String mit der Länge einer Zeile.
Nicht beutzte Zeichen werden mit leezeichen aufgefüllt.
Dann erst wird dieser zum Display übertragen.
Das bewirkt, falls Zeichen hinter der aktuellen Anzeige stehen bleiben, werden diese durch ein Leerzeichen überschrieben.
Noch was, die String Variable mus 1Byte länger sein, als eigentlich für die Zeichen benötigt werden, weil "C" noch ein String - Endezeichen einfügt.

RoboHolIC
09.11.2016, 17:13
Es scheint sich um ein Farb-Grafik-LCD, zu handeln. Da wird es ein paar mehr Möglichkeiten geben als bei einem Text-LCD. Der jetzige unerwünschte Modus ist eine Art additives Schreiben, oder eben mit ODER-Verknüpfung - auch das hat seine Berechtigung.

@HX8357C:
Klappere doch die Liste der textbezogenen Grafikbefehle bzw. Steuercodes nach irgendwas ab wie Texthintergrundfarbe, Transparenz, Löschung ab.

Unregistriert
09.11.2016, 19:12
hallo,
in den Examples wird offenbar
tft.fillScreen(HX8357_BLACK);
verwendet.
Auf anchen Displays (austesten!) funktioniert auch ein Zeilen-orientierter Befehl von

tft.setTextColor(HX8357_BLACK, HX8357_BLACK);

in Verbindung mit

tft.drawString(" ",x,y,f)

und dann wieder

tft.setTextColor(HX8357_BLACK, HX8357_WHITE);

was dann etwas schneller wäre als das ganze Display komplett zu löschen.

- - - Aktualisiert - - -

hallo,
in den Examples wird offenbar
tft.fillScreen(HX8357_BLACK);
verwendet.
Auf anchen Displays (austesten!) funktioniert auch ein Zeilen-orientierter Befehl von

tft.setTextColor(HX8357_BLACK, HX8357_BLACK);

in Verbindung mit

tft.drawString(" ",x,y,f)

und dann wieder

tft.setTextColor(HX8357_BLACK, HX8357_WHITE);

was dann etwas schneller wäre als das ganze Display komplett zu löschen.

- - - Aktualisiert - - -

ps,
der Link zum Code:
https://github.com/Bodmer/TFT_HX8357/blob/master/examples/HX8357_Char_times/HX8357_Char_times.ino

(wenn das auch deine lib ist)

DH4MBM
09.11.2016, 21:30
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-30-Display-Shield-fuer-Arduino
Es liest zwei Dallas-DS18B20 Temperatursensoren aus. http://playground.arduino.cc/Learning/OneWire
(https://arduion.cc)Auf beiden Seiten findet ihr die zugehörige library.

Hier nun der funktionierende 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));
}