Skip to content

Es(Pi)resso Part II: PID Temperature Control

Of course, what we really need is some means of replacing the lamentable stock brewing thermostat. The stock means of temperature control is remarkably inconsistent (it is, after all, a budget machine) and it will, perhaps more than anything else – aside from the availability of freshly and consistently ground coffee, of course – hamper our quest to espresso brewing perfection . We might even want to deal with the steam thermostat as well while we are at it.

I shan’t waste time explaining why, as I’m sure you all want to rush in to actually doing it, but the best way to achieve all of this is by implementing a Proportional-Integrative-Derivative (‘PID’) Controller1Catchy, I know..

It all sounds rather complex, but the hard work is mainly done, so we can achieve it fairly straightforwardly using the Pi. We need two pieces of hardware: a digital thermometer, which can be read by the Pi, to measure the temperature of the water in the boiler at any given time. We also need – and here is where things get rather dangerous, I’m not kidding – a solid-state relay (‘SSR’) to enable us to switch mains voltage upon command from the Pi.

The Thermometer

As others have done, I am going to be using a TSIC 306 digital thermometer to take temperature measurements from the boiler. It supports temperatures up to 150°C, which will be perfect for our needs. It runs from 3.3v which, again, is ideal.2It also, according to the data sheet will run from 5v and with greater accuracy. If you go down that line you’ll need to put in a voltage divider to bring the 5v from the data wire down to 3.3v to prevent damage to the GPIO.

The brewing thermostat sits on the side of the boiler. The steam thermostat is on top. We will be replacing the brewing thermostat with the TSIC 306. We will be leaving the steam thermostat in place for now, and allowing the Gaggia Classic to do its own work as far as controlling steam temperature goes. I say for now because ultimately it will be my intention to replace both thermostats, for reasons I shall come to describe.

My removed brewing thermostat, covered in thermal paste on the screw thread.

First, it’s wise to test your TSIC 306 in breadboard. Looking at the data sheet to make sure I connected everything up to the correct pins, I wired in 3.3v, ground, and the data wire went to GPIO 24 on the Pi3I know the picture below shows 23.

TSIC 306 in breadboard at B11-13

Using the standalone TSIC C++ application developed by James makes it easier, rather than compiling the whole gaggia/espiresso binary. You just need to install PIGPIO (which we will need anyway, for later). I will shortly provide instructions here for compiling and running this application, though it’s rather easy if you follow James’ instructions.

You should get consistent temperature readouts. Once you’ve confirmed everything works it’s time to package it neatly for installation into the Gaggia Classic.

First, get yourself some decent wire that’s rated for high temperatures – silicon is ideal, 22 AWG. I had an old analogue temperature sensor lying around, so I re-purposed the wiring. I soldered each wire to the TSIC 3064In my example, red is VCC, black is ground, and yellow is data, individually heatshrinking each pin. I then repeated my testing with the Pi, before heat shrinking the whole thing.

Next, get yourself an M4 hexagonal spacer (20mm length + 6mm thread).5Aluminium or brass, ideally. Carefully drill out the thread from the spacer to leave an opening wide enough for the TSIC 306 package to fit in to. Fill with a modest amount of good quality thermal paste, before placing in your TSIC 306. Then apply more heat shrink tubing to hold everything together. This will then screw directly into the side of the boiler where the existing thermostat is situated. Again, place a drop of thermal paste in the cavity in the boiler where the spacer screws in. This will ensure good thermal conductivity.

And, now screw it into the boiler!

TSIC 306 thermometer package, screwed in to the side of the Gaggia Classic boiler replacing the existing thermostat.

Run a final test on your Pi to ensure everything is still working – hopefully you should be reading the room temperature.6About 21 degrees for me.

At this stage, you will have the two terminal blocks which were previously connected to the thermostat just hanging loose. Those will, in time, be connected to the SSR. But, I personally wanted to do a quick test of the thermometer before proceeding, just to make sure everything was working at the high temperatures.

If you’re confident everything is working you can skip the next part, and move straight on to installing the SSR.

Up until this point your machine should have been switched off and unplugged. Shortly, we’re going to need to turn on the mains to see the results of our handiwork. This is where things get dangerous.

All the usual warnings about dealing with mains voltages apply. 

One wrong move, and it may well be your last. 

Be careful and take the proper safety precautions.

The old thermostat (that we’ve just replaced) functions exactly like a switch. The switch is closed, thereby allowing current to flow, up until the point that it reaches a set temperature for which the thermostat is calibrated.7That is why there are two thermostats, as the steam thermostat is rated for a higher temperature than the brewing thermostat. Once that predefined temperature is reached (within tolerances, and subject to huge fluctuations in these stock parts), the switch opens up thereby breaking the circuit and removing power to the boiler.

As things stand, removing the two wires from the thermostat, as we did, will permanently break the circuit, preventing power passing through to heat the boiler. If you turn your machine on in this state, with only the power switch (the lefthand most) turned ‘on8Obviously, being sure to use plastic caps on the terminal blocks to prevent any danger before doing so , the Gaggia Classic will be tricked into thinking that it has already reached brewing temperature and so the light on the brew switch – the righthand most switch – will be permanently illuminated indicating that there is no power going to the boiler.

Therefore, to test the thermometer sans SSR, ensure that the two terminal blocks removed from the thermostat are properly secured, ideally sealing them off using plastic caps, and away from danger. Then, turn on the power switch (left) and the steam switch (middle). This will short the brewing thermostat, the brewing light should turn off, and the boiler will begin to heat until it reaches steam temperature.

As it heats, you can then monitor the temperature on your Pi, as before. With any luck, the thermometer should respond as you would expect. Be warned, this will expose the TSIC 306 to high temperatures.

Once the thermometer reaches 100/120 degrees I would advise turning off the boiler (by turning off both switches and unplugging from the mains) for reasons I will come on to explain. Once you are satisfied the thermometer is working properly, then you’re ready to deal with the SSR.

Honey, I broke the thermometer…

I strongly advise not running the thermometer too high, perhaps not past 100/120 degrees initially. When I tested my thermometer (using these very instructions), I ran mine up to about 135degrees. At which point the binary on the Pi kept giving me identical readings. Very suspicious, I thought. I SIGINTed, I re-ran the programme, and realised that the thermometer had broken. I could no longer get any readings!

I’m not quite sure what happened , as the TSIC 306 is rated for 150degrees. But, given the inconsistency of the stock thermostats I wonder if, perhaps, there was some sort of temperature ‘spike’ which caused irreparable damage to the thermometer. Either that, or the thermometer wasn’t reading accurately and ‘130 degrees’ was actually 150+. In any event, I’m now waiting for my replacement to arrive, after which I shall investigate further. I will probably run it at 5v (for the greater accuracy, according to the manufacturer – not that I’d expect the voltage difference to result in a variance of 20 degrees!) next time.

I don’t actually intend to use steam (I really only drink espresso), but clearly this is not ideal. For the longer term I will think, whilst this new part arrives, about how to replace the steam thermostat as well. It shouldn’t be too hard. This would be easy if we just replaced the front button control panel altogether and installed 3.3v buttons. We could then just code the Pi to toggle between brewing/steam temperatures upon receiving a GPIO trigger, and run the boiler from the SSR as normal. If we want to keep all the stock switches working (which I would prefer), then that’s more difficult. Given they operate on mains AC, some further thought will be required as to how we do that. Probably just a transformer (e.g. mobile phone charger to 5v, plus voltage divider down to 3.3v?) to be triggered when the switch is in the on position. But, that’s for later. For now, I’m back to square one…
The temperature being read from the TSIC 306 (this is pre-death).

To be continued when my replacement thermometer arrives…

Published inEs(Pi)resso

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *