Author Topic: DIY PID using Arduino - Some data  (Read 2344 times)

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
DIY PID using Arduino - Some data
« on: March 07, 2017, 09:35:03 PM »
Hi, I've started working on a PID controller using an arduino based off of the Barebones coffee controller: http://playground.arduino.cc/Main/BarebonesPIDForEspresso.

I'm going to be using a TMP36 temperature IC that should have decent accuracy (+/- 1 deg C vs .35 deg C for the Auber RTD sensor). The slight issue I seem to be having, however, is that my preliminary data (measuring stock performance) seems to show that there isn't nearly as much temperature deviation as I was expecting.

.

Note that steep drops indicate times I am brewing (to warm up the grouphead) as well as a shot being pulled around the 900 sec mark. I do notice larger overshoots following water being pumped.

My data is showing temperature oscillations with an amplitude around 10 degrees Fahrenheit after initial warm up, which is rather low and I would say fairly adequate. This is perhaps due to the temperature sensor I'm using as well as the placement (I have it at the same level as the stock brew thermostat on the side of the boiler facing the rear of the case, at a distance from the heating element similar to the thermostat's distance. I've used thermal grease between the sensor and boiler surface and it's being help in place with an adhesive copper foil.

I'm sure the temperature measurement could be improved, perhaps by using the Auber sensor, but I'm not certain it would drastically change the data. I'm going to move forward with making the PID controller and see what results I can get and whether I can taste any difference.

Offline madd_extraction

  • Getting the Hang of It
  • **
  • Posts: 10
    • Classic, MDF,
    • Behmor 1600+
Re: DIY PID using Arduino - Some data
« Reply #1 on: March 08, 2017, 08:23:59 AM »
Interesting and good to know, thanks for sharing.

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
Re: DIY PID using Arduino - Some data
« Reply #2 on: March 13, 2017, 08:54:04 PM »
I got the PID controller working and am tuning it now. I've plotted the temp (blue) and heater power (duty cycle - red) vs time. The steep drops are when I'm brewing, the last one being a shot pulled. I did adjust the gains during the process which is why the response changes slightly.

I ran out of time and had to run to class but I'll be continuing trying to reduce the oscillations. It's about 2.5 deg F peak-to-peak which is quite a bit lower than stock but could be improved.

« Last Edit: March 13, 2017, 08:56:45 PM by chaosmint »

Offline nuclear_synthesis

  • Getting the Hang of It
  • **
  • Posts: 13
Re: DIY PID using Arduino - Some data
« Reply #3 on: March 13, 2017, 11:20:17 PM »
Power and temperature in antiphase indicate too much gain (proportional response). Reduce gain until you do not see oscillations.

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
Re: DIY PID using Arduino - Some data
« Reply #4 on: March 15, 2017, 11:24:07 PM »
So I've been doing a bit more work and I have independent PID control for steam and coffee (both set temps and gains). Basically I've shorted the steam thermostat and read the steam switch to see if it's "on." If the steam switch is pressed, the PID controller's inputs will be the steam settings.

Right now I'm focusing on the overarching "architecture" and have ordered all final parts. I'm going to have this completely enclosed within the Classic (using an Arduino mini in a small insulated box with a temp-activated fan) with a micro-usb port accessible through the rear vents for PID tinkering when I feel so inclined. I'm planning on controlling the brew switch light to indicate machine readiness rather than have a visible temp readout (unless of course tinkering through the arduino serial monitor).

Basically, I want the machine to look nearly completely stock but have improved functionality.


NOTE: Steep changes are due to water being pulled, steam activation, or large PID tuning changes.

Once it's all built and assembled I can bring the machine home from the lab where I work on it now and do a lot of actual taste testing and final tuning. I may adjust the PID algorithm itself. I think this current setup is prone to overshoot oscillations since there is natural heat loss from system. The PID wants to have decaying oscillatory behavior around 0 output power, but since it's impossible to send a negative output power (cooling the heating elements), it has to wait until it naturally cools back to the set temp.

Again, these corrections can be made in software when my machine is back at home making coffee in the morning, so I'm going to focus on hardware for now.
« Last Edit: March 15, 2017, 11:27:36 PM by chaosmint »

Offline The Big L

  • Grizzled GUG Veteran
  • *****
  • Posts: 421
    • Gaggia Classic (Raspberry PiD)
    • Pharos
Re: DIY PID using Arduino - Some data
« Reply #5 on: March 16, 2017, 09:37:30 AM »
The PID wants to have decaying oscillatory behavior around 0 output power, but since it's impossible to send a negative output power (cooling the heating elements), it has to wait until it naturally cools back to the set temp.

The PID shouldn't have to wait for a return to SV to start adding heat.  You should be able to tune your derivative gain to keep you very close to the SV.  My PID oscillates around the SV by about 0.1 deg F in either direction, and those tiny oscillations occur over a period of at least several seconds.  Going by memory, I think this corresponds to roughly a 3-4% duty cycle to compensate for heat loss through the boiler walls at equilibrium.

If you can't seem to tune your PID to achieve similar stability, I'd guess that the 10-bit resolution of the TMP36 may be too course for this application.  For this reason (among others) I chose the DS18B20 with a 12-bit resolution.

There may be ways to use the TMP36 that would flatten out your oscillations a bit.  According to this, you might be able to simply use the Arduino's 1.1V analogue voltage reference to get a higher resolution.  And you could also oversample -- average the results of hundreds of measurements per second to get a smoother measurement over time (more here).

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
Re: DIY PID using Arduino - Some data
« Reply #6 on: March 16, 2017, 02:49:12 PM »
I'll tune more and see how that goes but out of curiosity, a few questions:

1) How do you have that sensor physically mounted?
2) How do you go about "smoothing" your input temperature?
3) Does the digital read and calculation limit the speed of your controller at all? (I saw a TSIC 306 had a read function that said to NOT read during every loop)

Thanks for the help!

Offline The Big L

  • Grizzled GUG Veteran
  • *****
  • Posts: 421
    • Gaggia Classic (Raspberry PiD)
    • Pharos
Re: DIY PID using Arduino - Some data
« Reply #7 on: March 16, 2017, 03:29:56 PM »
I'll tune more and see how that goes but out of curiosity, a few questions:

1) How do you have that sensor physically mounted?
2) How do you go about "smoothing" your input temperature?
3) Does the digital read and calculation limit the speed of your controller at all? (I saw a TSIC 306 had a read function that said to NOT read during every loop)

Thanks for the help!

1) I cut a circuit board standoff screw (like this) in half, bored out the fat end, jammed the DS18B20 in there, and screwed it into the stock brew tstat position.
2) IIRC I'm sampling at 12-bits once a second, which has a 0.0625C resolution -- no need for smoothing
3) You'd have to experiment with your TMP36 and see how it works with oversampling.

BTW, I had forgotten that I had previously run into issues with DS18B20 at steaming temperatures.  Steaming temperatures (at least beyond about 260F) are above the limit for this sensor, and you might get inaccurate results and possibly a shorter part life if steaming often.  I don't steam much these days, so it hasn't really been an issue for me lately.  I actually have a TSIC 306 on hand, courtesy of fellow forum member peaberry who's using one in his PID.  If I ever get back into steaming, I might try out the TSIC which has a higher temp rating than the DS18B20.

Of course this is all irrelevant if you stick with the TMP36!

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
Re: DIY PID using Arduino - Some data
« Reply #8 on: June 03, 2017, 12:15:26 PM »
OK so I can posts some pictures soon but my machine's been done for a bit and I've finally got it back to my apartment.

In the end, I decided upon using a single relay to control power to the heater in coffee and steam modes. I read the steam switch to see if it's pressed and then change the set temp in the PID control function on my Arduino if it's pressed. This way I don't have to worry about having two relays that might be out-of-phase (even though the typical delay between is only 6ms, this is slightly more robust), nor do I have to perform two PID calculations and relay controls every loop.

One thing that I really like about this custom PID controller vs off-the-shelf controllers is feed-forward control! I can set my heater to 100% power until the temp is within 15 degrees (or any threshold) of my set temp. This makes warm-up and rebound time waaaay quicker than if you used PID control for the entire operational range.

I don't have a screen or anything outside of the machine, I simply watch the ready light to see as it transitions between PWM below my set temp and heater off above my set temp. Since I'm using an Arduino Mini (which has no on-board USB port), I was able to use an FTDI-to-microUSB board, whose port I have accessible through the rear vents so I can read the temp and adjust settings from a laptop if I so choose. I also power the arduino through a 120V-5V AV to DC converter inside the machine so my Classic looks stock other than the blinking ready light and the micro-USB port on the back.

My accuracy is still around +/- 1 deg, which I'm pretty happy with considering the temp drops several degrees once you start brewing anyway. I may fiddle with a different reference voltage but the resolution is somewhat limited by the sensor.

Like I said, I'll post some pictures soon and I can put some temp/power plots in case anyone has questions about how it works.

Offline laserchaseman

  • Just Got Here
  • *
  • Posts: 1
Re: DIY PID using Arduino - Some data
« Reply #9 on: July 04, 2017, 07:51:01 AM »
How is your system wired? I am working on adding Arduino to y gaggia as well and am not sure how to wire it so it can control both Brew and steam temperatures.

Offline chaosmint

  • Getting the Hang of It
  • **
  • Posts: 11
    • Gaggia Classic
    • Cunill Tranquilo Doser
Re: DIY PID using Arduino - Some data
« Reply #10 on: July 15, 2017, 07:42:58 PM »
How is your system wired? I am working on adding Arduino to y gaggia as well and am not sure how to wire it so it can control both Brew and steam temperatures.

I've attached the standard wiring diagram, which I'll reference in my explanation.

Quick explanation of the standard wiring of the Classic:
Switches 4 and 5 are bimetal thermostats, basic thermal control switches that are closed if they are below a certain temp and open if they are above a certain temp. Switch 7 is a connection that closes when you hit the steam switch on the front of the machine.

To answer your question:
My setup first off disconnects the left side of switch 7 and uses that as an input to the arduino so my arduino knows whether you're in coffee or steam mode. This drives the "set temp" in the controller. Next, I replace switch 4 and 5 and connect between the upper L node and the node above the heating elements 6 with a SSR (solid state relay). When I supply 5V from the arduino to the relay, the pilot light 11 is shorted and the heating elements get full power. By applying PWM (pulse width modulation), you can adjust the relative percentage of power that the heating elements receive each cycle. The way you choose the correct percentage of power in order to approach your set temp is through the PID control. The PWM output each cycle is a function of the current temp and the set temp (which, as I said before, is driven by whether or not you've hit the steam switch. The Arduino reads switch 7 and can tell which you want and choose the correct variable to refernce in the calculation), which the PID algorithm then uses and sends the output to the PWM loop.

Whew, that was quite the explanation but should hopefully solve a few of your follow-up questions; let me know if you have more!


 

LIBRARIES

Reference Library

Owners Manuals, Parts Diagrams, Wiring Diagrams, and How-To-Do-Stuff Articles.

 

+-Recent Topics

pressure issues with a 2003 Gaggia Classic by D4F
November 23, 2017, 09:43:46 PM

New Old Gaggia by MarkK
November 23, 2017, 08:24:41 PM

KitchenAid by Gaggia with double boilers--heard steam noise, unit got very hot.. by JojoS
November 22, 2017, 04:09:16 PM

Carezza Power Switch by Icstewart
November 20, 2017, 09:27:23 AM

BREW Button on 2003 Baby by JojoS
November 19, 2017, 08:28:04 PM

Can't knock coffee grounds out of filter basket by SusanJoM
November 19, 2017, 04:55:54 PM

Re: A conversation about brew pressure by JojoS
November 16, 2017, 01:04:32 PM

Can't find correct size shower screen by JojoS
November 16, 2017, 12:50:58 PM

Use OWC OEM portafilter for DIY pressure and/or temp gauge? by steveowc
November 14, 2017, 07:19:53 AM

OWC — Advice on mods to improve dispersion? by steveowc
November 13, 2017, 04:36:01 PM

Powered by EzPortal