From 99ef7af2e3320bb753b57e040e79e96b0d23cd67 Mon Sep 17 00:00:00 2001 From: Barb Date: Sun, 26 Mar 2023 16:09:37 +0200 Subject: [PATCH] added functional attiny45 code --- OpenEspresso_Core/OpenEspresso_Core.ino | 129 ++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 OpenEspresso_Core/OpenEspresso_Core.ino diff --git a/OpenEspresso_Core/OpenEspresso_Core.ino b/OpenEspresso_Core/OpenEspresso_Core.ino new file mode 100644 index 0000000..59b6849 --- /dev/null +++ b/OpenEspresso_Core/OpenEspresso_Core.ino @@ -0,0 +1,129 @@ +// +// Code written by Barb (Francesco Barbieri), March 2023, released as Open-Source. +// Functionality: Control a Nespresso/Delonghi and similar capsule/pod-based coffee maker +// I reused the original thermistor, but there's no reason why you couldn't pick your own +// +// Hardware required is minimal: +// - Arduino or compatible (I used an Attiny45 @8MHz) +// - 2 10A 250V Relay Modules +// - 230V AC to 5V DC 1A power-supply board (old phone charger will do, but ready-made modules exist) +// - Assorted resistors: the thermistor will require 10 or 100kOhm resistor, usually... +// - Some perf-board, wires, solder and soldering iron +// +//------------------------------------------------------------------------------------------ +// Values for temperature sensor assignment and calibration +int ThermistorPin = A1; +int Vo; +float R1 = 10000; // the actual resistor is 100K, but so is the thermistor, hence it's fine. +float logR2, R2, T, Tc; +float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; + +// Desired boiler temperature in C +int Tmax = 85; + +// Pumping Time for making Coffee (ms) +int PumpTime = 10000; + +// Digital Pin assignment for relays. +int BoilerPin = 0; +int PumpPin = 1; + +// Pin assignment for buttons +int OnPin = 5; // this is actually the reset pin and we'll only use it as such. +int MakePin = 3; + +// Green status LED under make coffee button +int LED = 4; + +//------------------------------------------------------------------------------------------ +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pins + pinMode(A1, INPUT); // A1 is the ADC we use to read the temperature from the thermistor + pinMode(OnPin, INPUT); // this is actually the reset pin and we'll only use it as such. + pinMode(MakePin, INPUT_PULLUP); + pinMode(BoilerPin, OUTPUT); + pinMode(PumpPin, OUTPUT); + pinMode(LED, OUTPUT); + digitalWrite(PumpPin, LOW); + digitalWrite(BoilerPin, LOW); + heat(); // heat once at boot and leave status LED on +} + +//------------------------------------------------------------------------------------------ +// the main loop function runs over and over again forever. +// Cointains control loops that call other functions +void loop() { + // read current temperature + temp(); + + // turn off status LED when boiler is too cold + if (Tc < (Tmax - 10)) { + digitalWrite(LED, LOW); + } + + // Make coffee when the green button is pressed + if (digitalRead(MakePin)==LOW){ + delay(100); // button debounce + heat(); // call heat function before making coffee + delay(100); // relay activation safety delay + digitalWrite(PumpPin, HIGH); // Pump + delay(PumpTime); // pump for pre-established time + digitalWrite(PumpPin, LOW); // stop Pumping + } +} + +//------------------------------------------------------------------------------------------ +// Boiler heating function +void heat() { + temp(); // Read current boiler temperature + while (Tc 150) { // if Tc is this high, thermocouple is probably shorted + error(); + } + else { + } +} + +//------------------------------------------------------------------------------------------ +// error function to lock the machine in a while loop until reset +// created to prevent overheating in case of failed thermistor +void error() { + while (true) { + // turn off all relays + digitalWrite(BoilerPin, LOW); + digitalWrite(PumpPin, LOW); + delay(1000); + // now blink the LED rapidly 5 times + for (int i = 0; i < 5; i++) { + digitalWrite(LED, HIGH); + delay(100); + digitalWrite(LED, LOW); + delay(200); + } + } +} +//------------------------------------------------------------------------------------------