Mind the toves. They can be a bit slithy. Don't even get me started on the borogoves.

Wednesday, April 9, 2008

LCD menu is working!

My latest struggle with the PID project has been getting the LCD menu system to work right. I was able to get the basic readout, showing temp, target temp, machine uptime, and heat power pretty easily. But I wanted to have a way to change the target, show the PID internal values, enter a standby mode, and adjust backlight level. I put some plain buttons in my project box and got them to work with the Arduino no problem, but getting the menus to work how I wanted has been trickier.

Not being a programmer, debugging has been a nightmare. I kept running into bizarre problems and having no idea where they were coming from. So I basically rewrote my LCD code. I also found a proper way to debounce my buttons and avoid double-presses. So now everything is working!

My next goal for this project is to attach a relay or sensor to the steam switch so I can have the PID control steaming temp, and the same for the brew switch, so I can tweak the control values during brewing and maybe put in a cute little little brewhead light so I can see what's going in the cup better. And also add a shot clock (just a readout, not actually turning off the brew process.) And I think after that, I may be done!

Saturday, March 22, 2008

Temperature problem solved ?

(This post refers to software from the Bare Bones Coffee Controller project by Tim Hirzel on the Arduino playground.)

So, I think I solved the problem with the temp sensing (see previous post). The thing that seems to have done it is to change the update interval to 2x per second from 5x:

#define PID_UPDATE_INTERVAL 500 // milliseconds

I re-read the PID without a PhD article, and it talks about sample rate. Since the boiler heater is a pretty slow-responding system, I figured I would try slowing down the rate that I grab a new temp for the PID process. I haven't changed how often the main loop checks the temp, so in effect, what I have done is increased the sample size that getFreshTemp() uses in averaging temps. But at this point, I don't really care, as long as it works. I'm also doing some extra smoothing with a simple algorithm I grabbed from the Arduino playground:

#define filterVal .2 //between 0 and 1 for smoothing function (small=more smooth)
float accum; //storage for smoothing function

float getFreshTemp() {
latestReading = (tcSum * multiplier / readCount) + 32.0;
accum = (latestReading * filterVal) + (accum * (1 - filterVal)); //smoothing function
latestReading = accum;
readCount = 0;
tcSum = 0.0;
return latestReading;


My performance is great now! The problem with the spikey temps was that they made the D factor essentially useless. Now, I've been able to tune the PID so that it stays within .5 deg +/-.

Friday, March 21, 2008

Temp sensing problems

Here's a little problem I'm having with the PID. My temp spikes every time the Arduino turns on the digital pin connected to the SSR (to turn on the heater). Here's what the graph looks like:

The measured temp goes up a couple of degrees when the Arduino is driving a digital pin attached to the SSR. Obviously, the actual temp isn't doing this. You can see that the duration of the error corresponds to the duty cycle - the upper part of the graph is wider when the SSR is on for a longer time, and thins out as the temp gets closer to the setpoint. I had thought this might be caused by the voltage dropping because of the heater sucking so much power (800 watts?) but it does the same thing when Silvia is powered off and unplugged. If I disconnect the (-) connection to the SSR, the error increases, but when I remove the (+) side, it goes away. Another strange error is that when my MacBook is plugged in to the AC adapter, the overall temp measurement goes up about five degrees. (I normally don't drag my adapter into the kitchen.) I've tried powering the Arduino from my adapter inside Silvia, an external adapter, an external adapter on a different circuit, and from the Mac's usb, all with the same result.

Because of the way the temp goes up when the Mac is plugged in, I wonder if this only happens when attached to the Mac. But I can't check this since I wouldn't be able to see the temp without the Mac. I may try to hook up my LCD display so I can monitor the temp without connecting to the Mac.

Friday, March 7, 2008

Some background on the PID project

When I first got my Silvia espresso machine about three years ago, I was really interested in all the mods people were doing. I did the pressure modification because it was relatively easy, cheap, and it seemed to me that it would improve my espresso. I really wanted to install a PID too, but I stopped short because using a commercial PID controller seemed overly expensive to me. So I learned to "reverse time surf" and made do with that for a long time. The problem with that is that it takes a long time between shots, and without a temperature readout, its still guesswork.

PID stands for proportional, integral, derivative, which are the elements of a formula for controlling a closed process (one input, one output) within a very tight range. The cruise control on your car is a PID controller. Basically the formula looks at the current error (distance from desired temperature) and adjusts the power to the heating element based on the sum of: the current error (P), the sum of errors over time (I) and the current rate of change of the error (D). For more details check out the wikipedia page on PID controllers.

The reason for using a PID to control the boiler on an espresso machine is that "perfect" espresso requires (among other things) a very specific temperature (depending on the coffee used) and the temperature must be kept as close as possible to that temp throughout the brewing process. The Silvia is a good candidate for a PID, since the temperature is already pretty stable for a relatively inexpensive home machine. (To get a more stable temp, you'd have to spend at least twice as much as Silvia.) In actuality, the PID has nothing to do with keeping the temp stable during the pour, it only helps the machine recover quickly without overshoot. Temp stability is a result of the thermal mass of the brass in the machine, which the Silvia has quite a lot of. The PID also makes it possible to precisely control the starting temp, which to me is the biggest advantage. Here's a blog that has some temperature plots so you can see the difference between PID and non-PID temperature ranges.

So, why am I doing this now? Hmmmm.... Well it started with the Make magazine video podcasts. I got addicted to them, and several of their projects used this thing called an "Arduino". I was like, "what the heck it that." I looked it up and found out it was an open source microcontroller. I had built a robot with a Basic Stamp several years ago, so my interest was piqued. Then, I ran across Tim Hirzel's and Nash Lincoln's blogs where they talked about using the Arduino for PID. Now all my lights were lit up.

As I've gotten into this, I think that if someone just wanted a simple PID, it would be easier to go the traditional route, using a dedicated PID controller. (Murph's PID page is the canonical reference.) There are several people selling "PID kits" that make it really simple. But the cool thing about using a full-blown microprocessor like the Arduino is that I can add as many features as I want. I plan to add a brewhead light that will light up during shots, using the PID to control steaming, and a custom LCD display. Tim and Nash have are taking it way further than that, doing things like using a nintendo controllers for remote control and more!

Thursday, March 6, 2008

About the DIY revolution

I saw this post by Clive Thompson yesterday on Wired. It really sums up a lot of what I love about tweaking and tinkering with stuff. I get a lot of intellectual stimulation from learning about stuff and how to fix it. I also like the idea of reusing things that would otherwise go in the landfill and not buying new unless I have to.

Wednesday, March 5, 2008

...and so it begins.

This is the beginning of my blog to talk about my "personal" projects. The one I'm on right now is putting a PID controller on my Silvia espresso machine, using on the Arduino microcontroller. I'm basing it on work done by Tim Hirzel at the Arduino playground.

The basic idea is to replace the stock brew thermostat with a solid state relay (SSR) to control the boiler heater. The SSR is controlled by a microcontroller running software that takes a temperature input from the boiler and through the PID formula, keeps the temperature in a very tight range, resulting in superior espresso. I plan to put details about the project in future posts.