program that worked with SSD1306 does not work with TFT screen anmore

Hi
First thing is - I have never done programming before so there is expected LOTS of junk code or/and small errors. With no experience at all what I basically did was take parts from other scripts and put them together in the way that it should work. Actually it did - sort of, with small screens (128x32 and 128x64). After I got TFT screen I obviously had to make some changes to the script and got it to work again but now the temp sensors start to throw lots of errors - even so, much that at some point watchdog does not trigger anymore!!? sometimes also txt in TFT freezes rotated 90 deg.
I have read somewhere that TFT library does not work properly with temperature sensors but I am not sure. As I said I have no experience at all.

At the moment I have no ideas what is wrong

This is a script I try to use with TFT screen. If somebody can make here proper fixes...

#define CHANNEL1 A1 //RelayIN1 kontakt A1

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <TFT.h>

//include watchdog lib
#include <avr/wdt.h>

// pin definition for TFT scrn
#define cs   10
#define dc   9
#define rst  8

// create an instance of the library
TFT screen = TFT(cs, dc, rst);

double count = 0;

const int buzzer = 7; //buzzer to arduino pin 7

// Data wire is plugged into pin 4 on the Arduino
#define ONE_WIRE_BUS 4
// 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);
DeviceAddress boiler = { 0x28, 0x9D, 0x14, 0x79, 0xA2, 0x0, 0x3, 0xE6 };
DeviceAddress ahi = { 0x28, 0x57, 0x48, 0xA2, 0x79, 0x1, 0x3, 0x8B };

void setup()
{
 //watchdog timer with 8 Seconds time out
 wdt_enable(WDTO_8S);

 //initialize the library
 screen.begin();

 // clear the screen with a black background
 screen.background(0, 0, 0);
 //set the text size
 screen.setTextSize(2);

 pinMode(buzzer, OUTPUT); // Set buzzer - pin 7 as an output

 sensors.begin();
 // set the resolution to 10 bit 
 sensors.setResolution(boiler, 10);
 sensors.setResolution(ahi, 10);

 Serial.begin(9600);
 float boilerTempC = sensors.getTempC(boiler);
 float ahiTempC = sensors.getTempC(ahi);

 pinMode(CHANNEL1, OUTPUT);
 }

void printTemperature(DeviceAddress deviceAddress)
{
 float tempC = sensors.getTempC(deviceAddress);

 if (tempC == -127.00) {
   Serial.print("Andmete lugemise viga...  Palun pöördu hooldusesse!"); // error if sensor fails
 } else {
   Serial.print(tempC);
   Serial.print(" C ");
 }
}

void loop() {

 screen.stroke(255, 255, 255);

 float boilerTempC = sensors.getTempC(boiler);
 float ahiTempC = sensors.getTempC(ahi);
 int boileroutTempC = (boilerTempC); // set when pump should stop
 int boileronTempC = (boilerTempC + 2); // set when pump should start
 int pumpTempErr = (boilerTempC + 30); // set buzzer start

 //Serial.print("Getting temperatures...\n\r");
 sensors.requestTemperatures();

 Serial.print("Boiler: ");

 printTemperature(boiler);
 Serial.print("\n\r");

 Serial.print("Ahi:    ");

 printTemperature(ahi);
 Serial.print("\n\r");

 // set buzzer if all fails and temp too high
 if (ahiTempC <= pumpTempErr) {
   tone(buzzer, 1000); // Send 1KHz sound signal...
   delay(1000);        // ...for 1 sec
   noTone(buzzer);     // Stop sound...
   delay(1000);        // ...for 1sec
 }
 else if (ahiTempC > pumpTempErr) {
   noTone(9);
 }
 else {
   noTone(9);
 }

 //tegeleme pumba loogikaga
 if (boilerTempC > ahiTempC) //Pump off if temp lowers
 {
   digitalWrite(CHANNEL1, HIGH);
   Serial.println("Pump väljas");

   //trükime ka ekraanile
   screen.setCursor(4, 90);
   screen.setTextColor(ST7735_RED, ST7735_BLACK);//kustutame eelmise info
   screen.print(F("Pump v")); screen.print((char)132); screen.print(F("ljas                "));//all that for ä char, alsoe tryng to use F in case of memory problems

 }

 if ( ahiTempC > boileronTempC ) //pump on
 {
   digitalWrite(CHANNEL1, LOW);
   Serial.println("Pump sees");

   //trükime ka ekraanile
   screen.setCursor(4, 90);
   screen.setTextColor(ST7735_GREEN, ST7735_BLACK);//delete previous loop txt
   screen.print(F("Pump sees                               "));

 }

 if (ahiTempC == -127.00) //if temp err run safety switch, Lülita pump sisse
 {
   digitalWrite(CHANNEL1, LOW);
   Serial.println("ERROR Pump sees");

   //trükime ka ekraanile
   screen.setTextWrap(true);
   screen.setCursor(4, 90);
   screen.setTextColor(ST7735_BLUE, ST7735_BLACK);//delete previous and set error colour
   screen.println(F("Anduri viga, pump on sees            "));
 }

wdt_reset();

 String vString =  String(ahiTempC,1);// set also decimal
 String bString =  String(boilerTempC,1);
 //String cString =  String(statusPump);

 robojaxText("Ahi:      ", 4, 50, 2, false);
 robojaxText(vString, 14, 70, 2, false);
 robojaxText("C   ", 103, 70, 2, false);
 robojaxText("Boiler:   ", 4, 5, 2, false);
 robojaxText(bString, 14, 28, 2, false);
 robojaxText("C   ", 103, 28, 2, false);
 count += 0.173;
 //delay(500);
}

 
/*
  robojaxText(String text, int x, int y,int size, boolean d)
  text is the text string to be printed
  x is the integer x position of text
  y is the integer y position of text
  z is the text size, 1, 2, 3 etc
  d is either "true" or "false". Not sure, use true
*/
void robojaxText(String text, int x, int y, int size, boolean d) {

 screen.setTextSize(size);
 screen.setCursor(x, y);
 screen.setTextColor(ST7735_WHITE, ST7735_BLACK);//delete screen
 screen.println(text);


} // LEAVE THIS ONE HERE FOR LOOP COMPLETION

please post your code within </> code-tags

I have read somwhere that TFT library does not work properly with temperature sensors but I am not sure. As I said I have no experience at all.

is the TFT screen, one of the SPI type ones ? If so yes i also think that if it is a touch-screen, it will not work together with any other SPI device on the same port.

One way to figure out why the watchdog timer is timing out is to put this line many place in loop().

  Serial.println(__LINE__); Serial.flush();

When the watchdog timeout occurs and the sketch restarts, the problem is somewhere between the last line number in Serial Monitor and the next Serial.flush().

Deva_Rishi:
please post your code within </> code-tagsis the TFT screen, one of the SPI type ones ? If so yes i also think that if it is a touch-screen, it will not work together with any other SPI device on the same port.

Yes, it is SPI, 1.8 inch 8pin no touch-screen. Is there any way to fix issue or is the only fix change the screen. If so what could be the working screen option?
Thnx

there is absolutely no relation between the onewire-sensors and tft-displays. As long as the TFT-display uses different IO-pins than the onewire-bus it can work. of course you can do a lot of things in your code that it does not work. but it is more unlikely. The mocrocontroller-world is not super-standardized like USB-devices. The wiring can cause the one-wire-bus to have unreliable communication.

Do you use a 4,7 kOhm-pullup-resistor between dataline and +Vcc-pin of the onewire-sensors?
on short wires the onewire-bus may have functioned without it.

Do you supply the onewire-sensors with +Vcc or do you use parasitic-powering?

If you have a wiring with pretty long wires more than 2 meters and even a topology that is similar to a star
this can cause communication problems too.
ideally a onewire-bus should be a signle three-wire cable GND, Data, Vcc with shortest possible branches to the sensors.

Connecting each sensor with long cables each cable starting from your arduino towards the sensor would be a "STAR-topology" if the STAR-topology is too long signal-reflections can cause the communication to fail.

best regards Stefan

In fact if it is about the capacitance of the cable, all lengths connected, need to be added up, regardless of the topology. With high speed data transfer capacitance can become an issue. Many times the solution that is chosen (thicker wires, less resistance) is the opposite of what may work as a solution (thinner wires, less capacitance)

StefanL38:
Do you use a 4,7 kOhm-pullup-resistor between dataline and +Vcc-pin of the onewire-sensors?
on short wires the onewire-bus may have functioned without it.

Do you supply the onewire-sensors with +Vcc or do you use parasitic-powering?

If you have a wiring with pretty long wires more than 2 meters and even a topology that is similar to a star
this can cause communication problems too.
ideally a onewire-bus should be a signle three-wire cable GND, Data, Vcc with shortest possible branches to the sensors.

Yes, I use a resistor, and yes I use +vcc onwire, and yes I have long data wire (I use cat5), but nothing of that should matter because all of this worked with OLED screens. I also changed the data pin after getting errors just to be sure. For me, the only logical thing is problems between TFT library and onewire or between screen and sensors. There could be also something drastically wrong with code - as I said I have never done this before.

Thanks

anyway you have to narrow down the problem. If you connect just one sensor with a short cable. Do oyu have the same result? if you reduce your code to the max read one sensor show value on the TFT-screen do then get the same results?