Temperaturanzeige mit TFT Display / Sensor einbinden

Servus Leute, bin momentan dabei eine Temperaturanzeige für ein kleines Projekt zu bauen. Jedoch habe ich nun das Problem, dass ich den zweiten Temperaturwert nicht auf das Display bekomme.
Setup:
-Arduino Nano
-MAX6675 mit Typ K Temperatursensor
-100K Thermistor
-1.77 Zoll SPI TFT Display 128x160
Der Wert vom MAX6675 wird bereits auf dem Display angezeigt, jedoch schaffe ich es nicht den Wert vom 100K Thermistor auf dem Display anzeigen zu lassen. Auf dem Serial Monitor kann ich beide Temperaturen sehen.
Das Programm ist aus mehreren Bibliotheken zusammengestellt und sieht ein wenig aus wie ein Schlachtfeld (bitte Steinigt mich nicht :grimacing: ).
Es geht um die zwei Zeilen " TFTscreen.text( ...X... , 0, 70);", hier muss anstatt dem X der Temperaturwert für den 100K Thermistor rein kommen, aber ich bekomm es irgendwie nicht gebacken. Ich hoffe ihr könnt mir da weiter helfen.
MfG Alex

#include "max6675.h"
#include <SPI.h>
#include <TFT.h>

int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
int vccPin = 3;
int gndPin = 2;
#define cs   10
#define dc   9
#define rst  8


//Thermistor 
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
//

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

TFT TFTscreen = TFT(cs, dc, rst);
char sensorPrintout[7];


void setup() {
  Serial.begin(9600);
  pinMode(vccPin, OUTPUT), digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT), digitalWrite(gndPin, LOW);

  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
//DISPLAY SETTINGS
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Temperatur ", 0, 0);
  //Wassertemperatur 2
  TFTscreen.text("Temperatur", 0, 50);

  // ste the font size very large for the loop
  TFTscreen.setTextSize(4);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
  
 
   // For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
   
  
  //DISPLAY LOOP
  // Read the value of the sensor on A0
  String sensorVal = String(thermocouple.readCelsius());
  

  



  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 7);




 
  // set the font color
  TFTscreen.stroke(255, 255, 255);
  //Wert für erste Temperatur
  TFTscreen.text(sensorPrintout, 0, 20);
  
    
  //Temperaturwert für die zweite Temperatur
  TFTscreen.text( ...X...  , 0, 70);
  delay(1000);
  //Wert eins löschen
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
  //  Wert zwei löschen
  TFTscreen.text( ....X.... , 0 , 70);
 
  

  //Thermistor 100k
  
  
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 

  Serial.print("Temperature: "); 
 
  Serial.print(Tc);
  Serial.println(" C");  
  


 
  

  

}

Hast wohl nicht verstanden, warum der erste Wert überhaupt zu sehen ist:
thermocouple.readCelsius() liefert eine Zahl

String s = String(x);
erzeugt ein String-Objekt aus dem Wert x.

s.toCharArray(sensorPrintout, 7);
kopiert den Text von s in den Puffer sensorPrintout (max 7 Buchstaben)

TFTscreen.text(sensorPrintout, 0, 20); schreibt diesen Text an die Position (0,20).

Den Zahlenwert hast du schon, in der Variablen Tc

Wie gehts dann weiter?

Sowas soll man nicht machen. Ausgangspins sind keine Stromversorgungspinns.
Benutze Masse und 5V Pin für Spannungsversorgung von externer Hardware. Soll ein Teil der Hardware ausgeschaltet werden muß zuerst alle Eingangspins stromfrei machen (Masse osder Hochohmig als Eingeng) und ein PNP / P-MOSFET zum abschalten.

Grüße Uwe

Okay, ich bin nicht so ganz in dem Arduino ding drin, aber ich meine zu verstehen was du meinst. Werde es später noch mal versuchen, falls was melde ich mich noch mal. Danke

So, habe es gerade eben probiert und es hat funktioniert. Danke für die Erklärung, jetzt weiß ich endlich was damit überhaupt gemeint ist.

#include "max6675.h"
#include <SPI.h>
#include <TFT.h>

int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
int vccPin = 3;
int gndPin = 2;
#define cs   10
#define dc   9
#define rst  8


//Thermistor 
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
//

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

TFT TFTscreen = TFT(cs, dc, rst);
char sensorPrintout[7];
char sensorOut[7];

void setup() {
  Serial.begin(9600);
  pinMode(vccPin, OUTPUT), digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT), digitalWrite(gndPin, LOW);

  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
//DISPLAY SETTINGS
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Temperatur ", 0, 0);
  //Wassertemperatur 2
  TFTscreen.text("Temperatur", 0, 50);

  // ste the font size very large for the loop
  TFTscreen.setTextSize(4);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
  
 
   // For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
   
  
  //DISPLAY LOOP
  // Read the value of the sensor on A0
  String sensorVal = String(thermocouple.readCelsius());
  String sensor = String(Tc);

  



  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 7);
  
  sensor.toCharArray(sensorOut, 7);



 
  // set the font color
  TFTscreen.stroke(255, 255, 255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  
    
  //Temperaturwert für zweite Temperatur
  TFTscreen.text(sensorOut, 0, 70);
  delay(1000);
  //erase the text you just wrote
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
  //  Wert zwei löschen
  TFTscreen.text(sensorOut , 0 , 70);
 
  

  //Thermistor 100k
  
  
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 

  Serial.print("Temperature: "); 
 
  Serial.print(Tc);
  Serial.println(" C");  
  


 
  

  

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.