Temperature control
intro
I wanted to demonstrate that temperature control using three of our boards would be easy. I will replicate this experiemnt at home to make a "sous vide" setup shortly.
Putting the hardware together
I took my ftdi_atmega
and used a standard 6 pin SPI cable to connect it to my spi_temp board.
The spi cable was then daisychained to the next board: spi_relay
The Relay was hooked up to an extension cord. This way the relay would control the power to the extension cord.
Next I hooked up the coffee pot to the extension cord.
and I extended the LM35 sensor (and waterproofed it). I put the sensor in the water in the coffee pot.
Writing the software
I took the spi_atmega demo application, and modified it to add temperature control. This was really easy:
if (wanted_temp && tchanged) {
long t0;
unsigned char heater;
static unsigned char curheater = -1;
t0 = SPI_getu16 (SPI_TEMP, 0x28);
//pputs ("t0 = ");hexshort (t0);
t0 = (t0 * 1000/11) >> 16;
// pputs (" t0 = ");hexshort (t0);
heater = (t0 < wanted_temp);
pputs (" t0 = ");hexshort (t0);
pputs (" wt = ");hexbyte (wanted_temp);
pputs (" heat = ");hexbyte (heater);
pputs (".\n\r");
if (curheater != heater) {
spi_setreg_u8 (SPI_RELAY, 0x20, heater);
curheater = heater;
pputs ("Turned heater ");
if (heater) pputs ("on");
else pputs ("off");
pputs ("\r\n");
}
}
This gets executed every second (because of the tchanged), It gets the temperature reading, converts it to centigrade and then compares it with the wanted temperature. In the mean time it logs some variables for debugging.
This is very simple on-off control. This, it turns out is not ideal with the slow response of the coffee machine. The temperature overshoots the intended temperature by quite a lot. This can be fixed by using a proper PID control algorithm. With a different heater setup this would not be necessary.