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