Hello all together
This is my first post in here and I just get up with a question...so I hope there is some help for me.
About me:
I like to work on DIY projects and this is where I get in contact with programming and especially programming the Arduino. Programming is not a passion for me just a way to solve a problem I am faced to. So I am one of those "copy and paste" programmers. I have some basic knowledge of programming (the 90's with Delphi and C...not much more), but I am not the god of programming my wife thinks I am
About the project:
I build myself a DIY Sous-Vide stick. Basically there is a heater (230V~) connected to an Arduino Uno via a SSR. A DS18B20 temperature probe is checking the water temperature the whole time. A 2.4 inch touch display allows me to set up the set-temperature of my water bath. On the other hand, the display has to show me the current temperature from the sensor.
The display works perfectly until I do anything with the temperature device. I can regulate the set-temperature by touch. But when the code for the sensor was inserted the following happened:
- the current temperature in the display will not change (it starts with the right temperature but does not update it)
- when I change the type of the temperature from int to float the display turns white after the first loop
I have a serial output listing the values at the same time, so I know it changes...
Might anybody be able to help?
Here's the code:
/* ####################################
* ##### DIY Sous-Vide controller #####
* ##### © 2016 by Wotild #####
* ####################################
*/
// library SPFD5408
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h> // Touch library
#include <OneWire.h> // onewire library
#include <DallasTemperature.h> // DallasTemperature Library
//Define pin 10 for Onewire Temperaturesensor (DS18B20)
#define ONE_WIRE_BUS 10
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Calibrates value
#define SENSIBILITY 1000
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905
//These are the pins for the shield!
#define YP A1
#define XM A2
#define YM 7
#define XP 6
// LCD Pin
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// Init TouchScreen:
TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY);
// Init LCD
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Assign human-readable names to some common 16-bit color values:
#define WHITE 0x0000
#define YELLOW 0x001F
#define CYAN 0xF800
#define MAGENTA 0x07E0
#define RED 0x07FF
#define GREEN 0xF81F
#define BLUE 0xFFE0
#define BLACK 0xFFFF
#define GREY 0x7BEF
// Dimensions
uint16_t width = 0;
uint16_t height = 0;
// Pin for the SSR to regulate the heater
#define SSR 13
//#### SETUP ####
void setup(void)
{
pinMode(SSR, OUTPUT);
digitalWrite(SSR, LOW);
// Start up the temp-sensor
sensors.begin();
// initialize the TFT
tft.reset();
tft.begin(0x9341);
tft.setRotation(1); // Need for the Mega, please change for your choice or rotation initial
tft.fillScreen(BLACK);
width = tft.width() - 1; // do not know what this is for
height = tft.height() - 1; // do not know what this is for
//DrawGrid(25); // a grid to help the grafical design of the GUI
StartScreen(); // draw the start screen
waitOneTouch(); // wait for a user input to proceed
MainScreen(); // draw the main screen
Serial.begin(9600); // initialize the Serial port
}
//Variables
int SollTemp = 55; // Set-temperature for the Sous-Vide
float IstTemp = 0; // is-temperature in the bath
int XX = 170; // some x-position on the TFT
TSPoint c; // a point used in the loop
int x, y = 0; // x and y coordinates to use
long Sekunden, Vergangen, alt = 0; // optional for a delay using the millis() command
//#### LOOP ####
void loop()
{
// print the values to verify what happens on the screen...
Serial.print(IstTemp, 1);
Serial.print("\t");
Serial.print(SollTemp);
Serial.print("\t");
Serial.println(Vergangen);
Sekunden = millis(); // set current "time" for the later delay
tft.setRotation(1); // seems important, if this is not here the screen toggles the orientation...
SollTemperatur(); // draw the set-temp screen
Vergangen = Sekunden - alt; // set the time of the current loop
if (Vergangen >= 2000) // if more than 2 seconds from the last update, update now
{
IstTemperatur();
alt = millis();
}
c = ts.getPoint(); // get the touch point
x = map(c.x, TS_MINX, TS_MAXX, 0, tft.width());
y = map(c.y, TS_MINY, TS_MAXY, 0, tft.height());
if (c.z > 0) // if there is some pressure
{
pinMode(XM, OUTPUT); //Pins configures again for TFT control...I do not know what this is for, but it does not work without
pinMode(YP, OUTPUT);
delay(200); // delay to allow the finger to go away :)
if ((x > XX) && (x < (XX + 63)) && (y > 10) && (y < 60))
SollTemp += 10;
if ((x > XX + 62) && (x < (XX + 62 + 63)) && (y > 10) && (y < 60))
SollTemp += 1;
if ((x > XX) && (x < (XX + 63)) && (y > 115) && (y < 115 + 50))
SollTemp -= 10;
if ((x > XX + 62) && (x < (XX + 62 + 63)) && (y > 115) && (y < 115 + 50))
SollTemp -= 1;
}
// set the SSR high or low depending on the temperature
if (IstTemp >= SollTemp)
digitalWrite(SSR, LOW);
if (IstTemp < SollTemp)
digitalWrite(SSR, HIGH);
}
// draw a price-winning start-up screen
void StartScreen(void)
{
tft.setCursor(20, 50);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.println("SousWiti");
tft.setCursor(210, 160);
tft.setTextColor(BLUE);
tft.setTextSize(2);
tft.println("TOUCH v2");
tft.setCursor(5, 230);
tft.setTextColor(YELLOW);
tft.setTextSize(1);
tft.println("C 2016 by Piti");
}
// draw the main screen with the buttons etc.
void MainScreen(void)
{
tft.fillScreen(BLACK);
//DrawGrid(25);
//Buttons
tft.fillRoundRect(XX, 10, 63, 50, 5, GREEN);
tft.fillRoundRect(XX + 62, 10, 63, 50, 5, GREEN);
tft.fillRoundRect(XX, 115, 63, 50, 5, RED);
tft.fillRoundRect(XX + 62, 115, 63, 50, 5, RED);
//Frame
tft.drawRoundRect(XX, 10, 63, 50, 5, WHITE);
tft.drawRoundRect(XX + 62, 10, 63, 50, 5, WHITE);
tft.drawRoundRect(XX, 115, 63, 50, 5, WHITE);
tft.drawRoundRect(XX + 62, 115, 63, 50, 5, WHITE);
//bakcground
tft.setTextColor(WHITE);
tft.fillRect(XX, 50, 125, 75, BLACK);
tft.drawRect(XX, 50, 125, 75, WHITE);
tft.setTextSize(5);
tft.setCursor(XX + 18, 13);
tft.print("+");
tft.setCursor(XX + 18 + 63, 13);
tft.print("+");
tft.setCursor(XX + 18, 127);
tft.print("-");
tft.setCursor(XX + 18 + 63, 127);
tft.print("-");
}
// draw/print the set-temperature
void SollTemperatur(void)
{
tft.setTextColor(WHITE, BLACK);
tft.setCursor(10, 70);
tft.setTextSize(5);
tft.print("Soll");
tft.setCursor(XX + 18, 59);
tft.setTextSize(8);
if (SollTemp > 90) SollTemp = 90;
if (SollTemp < 20) SollTemp = 20;
tft.print(SollTemp);
}
// get and draw/print the is-temperature
void IstTemperatur(void)
{
tft.setTextColor(WHITE, BLACK);
tft.setCursor(10, 180);
tft.setTextSize(5);
tft.print("Ist ");
tft.setCursor(XX + 8, 180);
//request the temp from the sensor
sensors.requestTemperatures();
// store the current temp in the variable
IstTemp = sensors.getTempCByIndex(0); // sensor.getTempC() does not work :(
// if the set temperature is below the current temp, the number should be printed in alarming red color...
if (IstTemp <= SollTemp)
tft.setTextColor(WHITE, BLACK);
else
tft.setTextColor(RED, BLACK);
// print the current temperature with one floating digit
tft.println(IstTemp, 1);
}
// some helping funtcion I build to help to draw things
void DrawGrid(int Step)
{
for (int i = Step; i <= width; i += Step) {
tft.drawLine(i, 0, i, height, GREY);
tft.drawLine(0, i, width, i, GREY);
}
}
// wait 1 touch to return the point
TSPoint waitOneTouch() {
TSPoint p;
do {
p = ts.getPoint();
pinMode(XM, OUTPUT); //Pins configures again for TFT control
pinMode(YP, OUTPUT);
} while (p.z < 500);
}
Thanks in advance!!!