|
|
@ -9,9 +9,8 @@ String readString; |
|
|
|
// Code must be adjusted accordingly if a PTC resistor is used once more!
|
|
|
|
int Vo; |
|
|
|
float R1 = 10000; // <-- change this value to the resistance of the fixed resistor (so don't change PLS!)
|
|
|
|
float logR2, R2, T, Tc, Told; |
|
|
|
float logR2, R2, T, Tc, Tp, Tstart, Told; |
|
|
|
float c1 = 8.5e-04, c2 = 1.85e-04, c3 = 2e-07; // Here's where you can perform actual calibration
|
|
|
|
|
|
|
|
// Variable to store desired Max boiler Temp
|
|
|
|
int desiredTemp = 70; |
|
|
|
|
|
|
@ -19,7 +18,6 @@ int desiredTemp = 70; |
|
|
|
int unrecoverableErr = 0; |
|
|
|
int warning = 0; |
|
|
|
int warned = 0; // support variable needed to prevent arduino from making second coffee after refill. this is a shitty hack and resets the board.
|
|
|
|
|
|
|
|
// Variables for cleaning and other maintenance
|
|
|
|
int dry = 0; |
|
|
|
int noCoffee = 0; |
|
|
@ -31,13 +29,11 @@ int timeratio = 1; |
|
|
|
int pumpRatio = 15; // warning: there is usually ~5s dead time from pump startup to water flowing out of nozzle
|
|
|
|
// This next variable is used to get current "time" in ms and break out of while cycles that need a time limit safeguard
|
|
|
|
unsigned long startTime; |
|
|
|
unsigned long pMillis; |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void(* resetFunc) (void) = 0; // declare reset fuction at address 0
|
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
// put your setup code here, to run once:
|
|
|
|
// first we set pins as I/O and initialize outputs LOW
|
|
|
@ -53,7 +49,6 @@ void setup() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void loop() { |
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
digitalWrite(greenLED, HIGH); |
|
|
@ -86,33 +81,32 @@ void loop() { |
|
|
|
//if (incomingData == "read") {
|
|
|
|
//digitalWrite(greenLED, HIGH);
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (incomingData == "rist") { |
|
|
|
// set parameters for ristretto:
|
|
|
|
delay(100); |
|
|
|
Serial.write("Ristretto\n"); |
|
|
|
pumpRatio = 10; |
|
|
|
pumpRatio = 15; |
|
|
|
} |
|
|
|
|
|
|
|
if (incomingData == "espr") { |
|
|
|
// set parameters for espresso:
|
|
|
|
delay(100); |
|
|
|
Serial.write("Espresso\n"); |
|
|
|
pumpRatio = 15; |
|
|
|
pumpRatio = 20; |
|
|
|
} |
|
|
|
|
|
|
|
if (incomingData == "long") { |
|
|
|
// set parameters for lungo:
|
|
|
|
delay(100); |
|
|
|
Serial.write("Lungo\n"); |
|
|
|
pumpRatio = 20; |
|
|
|
pumpRatio = 25; |
|
|
|
} |
|
|
|
|
|
|
|
if (incomingData == "amer") { |
|
|
|
// set parameters for lungo:
|
|
|
|
delay(100); |
|
|
|
Serial.write("Americano\n"); |
|
|
|
pumpRatio = 50; |
|
|
|
pumpRatio = 60; |
|
|
|
} |
|
|
|
|
|
|
|
// check if the incoming data is "make":
|
|
|
@ -187,7 +181,7 @@ void loop() { |
|
|
|
|
|
|
|
// making steam:
|
|
|
|
while (digitalRead(vaporSensorPin) == HIGH) { |
|
|
|
desiredTemp = 90; |
|
|
|
desiredTemp = 100; |
|
|
|
Serial.write("Vapor heating\n"); |
|
|
|
delay(500); |
|
|
|
Heat(); // Heat the boiler to vapor temperature
|
|
|
@ -201,7 +195,6 @@ void loop() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
// this is how we read the input
|
|
|
|
void serialRead() { |
|
|
|
while (Serial.available()) { |
|
|
@ -213,7 +206,6 @@ void serialRead() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void Grind() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
delay(100); |
|
|
@ -242,7 +234,6 @@ void Grind() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void Drop() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
delay(100); |
|
|
@ -256,18 +247,19 @@ void Drop() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void Heat() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
digitalWrite(redLED, HIGH); |
|
|
|
startTime = millis(); |
|
|
|
pMillis = startTime; // value to store
|
|
|
|
delay(100); |
|
|
|
Serial.write("Heating to "); |
|
|
|
delay(100); |
|
|
|
Serial.print(desiredTemp); |
|
|
|
delay(100); |
|
|
|
Tc = 0; |
|
|
|
Told = - 100; |
|
|
|
Tc = 0; // current temperature
|
|
|
|
Tp = -10; // temperature at previous cycle
|
|
|
|
Tstart = - 100; // temperature at start of Heat() function
|
|
|
|
|
|
|
|
// monitor temperature and adjust boilerPin as needed:
|
|
|
|
while (true) { |
|
|
@ -280,56 +272,76 @@ void Heat() { |
|
|
|
Tc = (T - 273.15); |
|
|
|
|
|
|
|
if (millis() - startTime == 1000) { |
|
|
|
Told = Tc; // support variable to store temp at beginning, so that we can be sure it's increasing
|
|
|
|
Tstart = Tc; // support variable to store temp at beginning, so that we can be sure it's increasing
|
|
|
|
} |
|
|
|
|
|
|
|
// check if temperature is within the acceptable range and break out of the loop without error if done heating:
|
|
|
|
if (Tc > desiredTemp) { |
|
|
|
// temperature is within range, so break out of the loop:
|
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
delay(100); |
|
|
|
Serial.write("reached desired temp\n"); |
|
|
|
delay(100); |
|
|
|
Serial.print(Tc); |
|
|
|
delay(100); |
|
|
|
digitalWrite(redLED, LOW); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (Tc < -100) { |
|
|
|
delay(100); |
|
|
|
Serial.write("u-Thermocouple: unplugged or failed\n"); |
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
unrecoverableErr = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (millis() - startTime > 20000 && Tc - Told < 1) { |
|
|
|
if (millis() - startTime > 20000 && Tc - Tstart < 1) { |
|
|
|
delay(100); |
|
|
|
Serial.write("p-Thermocouple: positioning or relay fault\n"); |
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
unrecoverableErr = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (millis() - startTime > 30000) { |
|
|
|
if (millis() - startTime > 60000) { |
|
|
|
delay(100); |
|
|
|
Serial.write("h-taking too long, continuing...\n"); |
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
digitalWrite(redLED, LOW); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// We do this at the end so that the relay is not uselessly cycled
|
|
|
|
digitalWrite(boilerPin, HIGH); |
|
|
|
|
|
|
|
// actual heater logic follows:
|
|
|
|
// check aprox. derivative every second and shut off heater if temperature is increasing too quickly!
|
|
|
|
// conversely, heater is turned on if temperature is not incresing quickly enough
|
|
|
|
if (millis() > (pMillis + 1000)){ |
|
|
|
|
|
|
|
if (Tc < (desiredTemp - 20)) { |
|
|
|
digitalWrite(boilerPin, HIGH); |
|
|
|
} |
|
|
|
|
|
|
|
else if ((Tc - Tp) < 0.5) { |
|
|
|
digitalWrite(boilerPin, HIGH); |
|
|
|
} |
|
|
|
|
|
|
|
//else if ((Tc - Tp) > 1) {
|
|
|
|
// digitalWrite(boilerPin, LOW);
|
|
|
|
//}
|
|
|
|
|
|
|
|
else { |
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
} |
|
|
|
|
|
|
|
Tp = Tc; |
|
|
|
pMillis = millis(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
delay(milliseconds); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
|
digitalWrite(redLED, LOW); |
|
|
|
digitalWrite(greenLED, HIGH); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void Press() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
delay(100); |
|
|
@ -364,7 +376,6 @@ void Press() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void unPress() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
delay(100); |
|
|
@ -399,7 +410,6 @@ void unPress() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void Pump() { |
|
|
|
digitalWrite(greenLED, LOW); |
|
|
|
delay(100); |
|
|
@ -416,17 +426,15 @@ void Pump() { |
|
|
|
} |
|
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
|
|
|
|
|
|
void makeCoffee() { |
|
|
|
// code to make coffee goes here...
|
|
|
|
// It would be much smarter to break down complicated functions into subroutines: press/unpress etc...
|
|
|
|
// Hence that's what we'll have done by the time the first release goes public ;)
|
|
|
|
// makeCoffee() can still run all the same, but clean() can use the same press/unpress code!
|
|
|
|
// care must be taken to place these functions earlier in the code, or the compiler will rightfully freak out
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
desiredTemp = 75; |
|
|
|
desiredTemp = 85; |
|
|
|
Heat(); // First we pre-heat the boiler
|
|
|
|
if (unrecoverableErr == 1) { |
|
|
|
break; |
|
|
@ -479,19 +487,18 @@ void makeCoffee() { |
|
|
|
delay(1000); |
|
|
|
|
|
|
|
Press(); // Self explainatory
|
|
|
|
|
|
|
|
if (unrecoverableErr == 1) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
desiredTemp = 85; |
|
|
|
desiredTemp = 95; |
|
|
|
Heat(); // First we pre-heat the boiler
|
|
|
|
if (unrecoverableErr == 1) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (dry == 0) { |
|
|
|
digitalWrite(boilerPin, HIGH); |
|
|
|
//digitalWrite(boilerPin, HIGH);
|
|
|
|
delay(100); |
|
|
|
Pump(); // Pump ratio (in seconds) will be read from serial input in final release
|
|
|
|
digitalWrite(boilerPin, LOW); |
|
|
@ -499,7 +506,6 @@ void makeCoffee() { |
|
|
|
delay(3000); // Allow pressure to wane
|
|
|
|
|
|
|
|
unPress(); // unpressing the press to reset the machine
|
|
|
|
|
|
|
|
if (unrecoverableErr == 1) { |
|
|
|
break; |
|
|
|
} |
|
|
|