# Gaggia Classic / Raspberry Pi / Pressure Sensor



## ds_gaggia (Mar 14, 2016)

I made a few changes to my Raspberry-Pi-controlled Gaggia Classic over the last couple of weeks (for context: orginal post on the Gaggia Users Group here; old demo video here).

One thing that was bugging me with this setup was that I wasn't able to measure pressure inside the group during extraction. I was curious about determining how to end preinfusion based on pressure readings, understanding puck resistance during the shot, and playing with declining flow profiles, etc. I didn't want to put a pressure transducer right after the pump (since there are tiny holes / valves acting as flow restrictors along the way to the group), and I was a bit intrigued by what Decent Espresso had achieved re: measuring pressure at the puck, and the kinds of shot diagnostics this could lead to.

When @FairRecycler announced last month that his pressure gauge block was ready, I got in touch with him, and he offered to send me a pressure transducer with all the fittings in place. Kudos to him! I now have a transducer reading pressure right after the 3-way valve and before the group. After installing everything last weekend (all I had to do was hook up the transducer output wire to my analog-to-digital converter, with 2 resistors to divide output voltage) and fixing my (horribly-written) Python code, I am able to read pressure during the shot.

Here's an example of a shot I made yesterday (link): the video is a capture of my Raspberry Pi / 2.8" display during the shot. The shot goes in 4 stages:



I start by running the pump at 60% for the first 4 seconds of the shot (achieving a quick ~6 mL/sec preinfusion, if I read the pump specs correctly). Pressure rises to about 3 bar (green curve).


4-11 sec into the shot: the pump goes to 0% (with the solenoid still open), and we wait. Pressure goes down a bit as the puck starts absorbing water (I guess).


11-14 sec: the pump goes to 100% and pressure rises very quickly to 9.5 bar.


from 14 sec until the end of the shot: the pump slows down to 10% (essentially skipping 9 A/C cycles out of 10); pressure goes down as the puck erodes (maybe some channeling as well, I can't tell...), reaches 3 bar at 40 seconds.


The pressure appears to be fluttering a bit in the last phase of the shot as the pump pushes water ~6 times per second (rather than 60 -- I'm in the US so A/C runs at 60Hz). This might make it difficult to diagnose channeling live.

(Don't pay too much attention to the output flow rate -- the red/pink line and area in the video; it's based on my scale readings which are very noisy -- something is shaking a bit too much inside the machine, and the vibrations are what's causing noisy flow readings; I'll have to fix this...).

Overall I'm really pleased with this setup: it's giving me some ideas for experimentation. Right now, I can only create very simple "pump profiles" as above (where I only determine the pump power as a function of time and/or observed flow in the cup -- which by itself is just a lagging indicator or what's happening in the puck...), but I might be able to achieve better control and more interesting shots by driving the pump based on time, pressure, and/or flow out of the pump.


----------



## phario (May 7, 2017)

ds_gaggia said:


> I made a few changes to my Raspberry-Pi-controlled Gaggia Classic over the last couple of weeks (for context: orginal post on the Gaggia Users Group here; old demo video here).
> 
> One thing that was bugging me with this setup was that I wasn't able to measure pressure inside the group during extraction. I was curious about determining how to end preinfusion based on pressure readings, understanding puck resistance during the shot, and playing with declining flow profiles, etc. I didn't want to put a pressure transducer right after the pump (since there are tiny holes / valves acting as flow restrictors along the way to the group), and I was a bit intrigued by what Decent Espresso had achieved re: measuring pressure at the puck, and the kinds of shot diagnostics this could lead to.
> 
> ...


 This is really amazing work. Will you share the current Github code for your scripts? I noticed the one that's linked on YouTube is a bit outdated.

This is a random question, but how do you feel about the PiTFT 2.8" screen (which I assume you're using?). I recently bought the 2.4" hat version and I haven't installed it, but I'm getting a few pangs of "Should I have gone for the 2.8 version"?


----------



## ds_gaggia (Mar 14, 2016)

Yes, I will update the code on GitHub. And hopefully clean it up a little bit as well!

About the 2.4" vs. 2.8" screen: I think both screens have the same resolution (320 * 240), but everything will look a bit tinier on the 2.4". I was actually thinking I should have gone for the 3.5", or even the bigger 7" version...


----------



## phario (May 7, 2017)

ds_gaggia said:


> Yes, I will update the code on GitHub. And hopefully clean it up a little bit as well!
> 
> About the 2.4" vs. 2.8" screen: I think both screens have the same resolution (320 * 240), but everything will look a bit tinier on the 2.4". I was actually thinking I should have gone for the 3.5", or even the bigger 7" version...


 Thanks!

It's a bit annoying to wonder about those things because I think the 2.4 or 2.8" screens aren't cheep (are you buying the 'official' Adafruit ones or off brand ones?

It's also annoying that the prices are somewhat random according to the screen size. There are some really nice 4" and 3.5" screens with better resolution that are not much more expensive.


----------



## ds_gaggia (Mar 14, 2016)

Yes, I went for the Adafruit display. They are a bit more expensive than off-brand displays; but not having to worry about finding the right drivers, etc. is nice. I also really like the fact that they've put 4 buttons on the side -- something else that I didn't have to think about! And I've learned a ton from their tutorials over the years, so I'm happy to support them, even if I could probably find slightly better deals elsewhere.

Overall, these kinds of projects aren't super cheap: you start by getting a RPi, then you get a display, breakout boards for various things, some components. None of these things are very expensive on their own, but they add up. Cost-wise, it's hard to beat an off-the-shelf PID and a light dimmer to control the temperature and the pump.


----------



## phario (May 7, 2017)

ds_gaggia said:


> Yes, I went for the Adafruit display. They are a bit more expensive than off-brand displays; but not having to worry about finding the right drivers, etc. is nice. I also really like the fact that they've put 4 buttons on the side -- something else that I didn't have to think about! And I've learned a ton from their tutorials over the years, so I'm happy to support them, even if I could probably find slightly better deals elsewhere.
> 
> Overall, these kinds of projects aren't super cheap: you start by getting a RPi, then you get a display, breakout boards for various things, some components. None of these things are very expensive on their own, but they add up. Cost-wise, it's hard to beat an off-the-shelf PID and a light dimmer to control the temperature and the pump.


 Or in my case, a million temperature sensors (digital, analog, PT100, thermocouple, etc.) and my dreams have degraded into a temperature probe comparison project. As you say, the individual components aren't expensive, but it adds up very quickly. Sometimes, it's just those misc. components like standoffs to create a sensor or components to read in the sensor data.

Two more questions/points:

I wonder if the max temperature issue on the DS18B20 will cause yours to degrade over time (even if it's not operational during the steam time). There were some scattered reports by people that the TSIC 306 would eventually fail, even with a max of 150C. The TSIC 306 is the only suitable digital sensor I know of that can get up to steam temperatures.

Are there other ways to do the pump modulation?


----------



## phario (May 7, 2017)

Oh and also do you happen to have a copy of your Coffee Hustle post?

https://coffeehustle.com/posts/q9EmQBBtPDKvFBGfv/controlling-espresso-extraction-through-real-time-flow-rate

It's not obtainable on the Wayback Machine and I'm eager to get it.


----------



## ds_gaggia (Mar 14, 2016)

Unfortunately, Matt Perger shut down Coffee Hustle a couple of months after I posted this, and I don't have a copy... I thought I originally wrote it in a file on my laptop, but I can't find it any more... 😞

About temperature sensors: I switched from the DS18B20 to an RTD PT-100 sensor sometime last year, so I wouldn't have to worry about exceeding the max temperature rating. Turns out there is a breakout board for RTD sensors (MAX 31865), and I was able to make it work with my Raspberry Pi using this library on GitHub. I'm happy with the results (I can steam milk without frying my temperature sensor).

About pump control: there are definitely other ways to do this. You're probably familiar with this project, which uses an IGBT to chop off the AC sine waves, but I wasn't too confident in my ability to work with high voltage AC. That's why I ended up driving the pump through a simple zero-crossing SSR. I only switch a GPIO output pin high or low for the duration of each AC wave (0.02 sec. with 50Hz AC; 0.01666 sec. with 60Hz) in a predefined sequence, so the pump keeps turning on and off (the magic happens in this function). It's not very elegant, but it does the job fairly well...


----------



## phario (May 7, 2017)

ds_gaggia said:


> Unfortunately, Matt Perger shut down Coffee Hustle a couple of months after I posted this, and I don't have a copy... I thought I originally wrote it in a file on my laptop, but I can't find it any more... 😞
> 
> About temperature sensors: I switched from the DS18B20 to an RTD PT-100 sensor sometime last year, so I wouldn't have to worry about exceeding the max temperature rating. Turns out there is a breakout board for RTD sensors (MAX 31865), and I was able to make it work with my Raspberry Pi using this library on GitHub. I'm happy with the results (I can steam milk without frying my temperature sensor).
> 
> About pump control: there are definitely other ways to do this. You're probably familiar with this project, which uses an IGBT to chop off the AC sine waves, but I wasn't too confident in my ability to work with high voltage AC. That's why I ended up driving the pump through a simple zero-crossing SSR. I only switch a GPIO output pin high or low for the duration of each AC wave (0.02 sec. with 50Hz AC; 0.01666 sec. with 60Hz) in a predefined sequence, so the pump keeps turning on and off (the magic happens in this function). It's not very elegant, but it does the job fairly well...


 Cheers, I absolutely hate it when information is lost in that fashion. If you have a moment, it would be nice to hear 1-2 paragraphs of what you remember of that CoffeeHustle discussion.

Regarding temperature sensors, I have the same MAX31865 and actually I have a question that I'd love for your help on. From what I understand it, the MAX31865 board uses your Rpi SPI pins. However, the PiTFT screen uses this SPI interface. As I understand it, you can have multiple devices on these pins, but:



Can you explain how you physically wire it? I guess you don't use the 2x20 GPIO header on your 2.8" screen and instead just attach individual wires? It would be really good if you could provide a picture inside your box.


Can you explain what modification would be necessary to run the MAX31865 in conjunction with the PiTFT?


----------



## ds_gaggia (Mar 14, 2016)

Sure, happy to help.

I use a GPIO ribbon cable, which I connect from the back of the 2.8" screen to my board (no individual wires). To prototype, something like this really helps. The screen uses the hardware SPI interface, which means that you can't use GPIO 7, 8, 9, 10, 11 (these are the BCM pin numbers, not physical pin numbers -- pinout here) for the MAX31865; but you can create a software interface instead using free GPIO pins. I ended up connecting mine to GPIO 6, 14, 15 and 21 on the board; and using the max31865 github code, I can communicate with it by doing:



> GPIO.setmode(GPIO.BCM)
> 
> clkPin = 14
> misoPin = 15
> ...


 Here are 2 photos of my board and RPi if this can help.


----------



## therealgdanov (Apr 28, 2021)

great thread and great links! Would you care to share the transducer you are using? 99% of the ones I find are with a conical thread and I can't figure out how to connect them to the rest of the armature that's 1/8 NP (I guess).


----------

