DIY PID controller for Log

iScrtAznMan

New Member
I had a discussion thread that stopped being a discussion, so I'm restarting as DIY:

If there's interest I don't mind to share my code, however it's still pretty rough and I would like to clean it up a bit more before sharing. I believe making it public is the best way for it to improve (a lot of you know more than I do), but I don't want to be associated with the mess it is now. It's also not too hard to build it from scratch if you know what you're doing. It just ends up taking me forever because I'm normally doing some manually verification testing, if you know what I mean.

The way I have it setup currently is with the Adafruit Max 31856 TC amplifier, 2 IRLZ44s, a TC4428 to drive the mosfet for the log, and a bunch of pull down resistors. I'm using a K-type thermocouple that you can also get off Adafruit shoved against the heater, but I'm trying to get something better. I coded everything in Python, but will probably make a pretty webapp for the client once I finish the controller logic. Currently the client is also in python and it's all over UDP. It's not super complicated but I spent a lot of time reading about why my mosfets got hot (just spend the $1 on an IC to do . . . ). I'm running the mosfets right now at 50kHz and have no issues at 35V which pulls 1.745A or 61.59W. If I got rid of the terrible Circuit Python libraries, I could probably go higher but there's not much point. At idle it pulls around 4W.

The biggest limit right now is the TC lag (the amplifier takes somewhere around 50ms-100ms to do the analog conversion) and the fact that my TC is touching the heater and outer wall. The Omega TC I got are unsheathed and I need to figure out how to insulate them (most likely switch to a glass heater). It currently has about 5-10s of lag. 5 seconds during a hit with Tu around 13s (distance between oscillations at Ku for Ziegler-Nichols tuning). This makes Kd pretty important to help kickstart and stop the heater. At my draw rate, I notice a 20C temp swing that seems pretty constant. Without preheating, it drops 20C. It also will overshoot 20C once you stop drawing if you are at the setpoint. It's probably possible to find a pattern and implement a stead state error when idle, but just increasing the airpath distance on the heater is better. Maybe just steal an old volcano heater if you can find one cheap. I want to DIY something smaller though. Maybe a U-pipe.

Is it cost effective? Probably not, but if you only buy the parts you need you could probably do it for $50 if you already have a variable DC Power Supply (or if you have a laptop power supply). Lower if you feel comfortable building your own TC amplifier. Or you could just go buy a box mod . . . Is it safe? Probably not but I'm trying to get it as safe as possible. I don't feel comfortable leaving it on unattended but it also takes like 30s to heat up. However, I do see a lot of room to play and improve the system. The biggest reason I'm doing this is so I can customize however I want because I have the code and most vapes have shit code that can't really be modified or it's all closed sourced and you have no way to trust it. Pretty sure some of you out there are smarter than me and could make improvements.
 
Last edited:
iScrtAznMan,
  • Like
Reactions: KeroZen

Abysmal Vapor

Supersniffer 2000 - robot fart detection device
There are cartridge heater with a probe inside ,like those for rosin plates ;), i suggest you take a look at those,but IMO ,in some builds it would be batter to control the temp based on resistance curve (Check RTD temp sensors). Another great source would be the Bud Toaster thread,now Herb Cube by @Hippie Dickie,he also has custom PID control ,which might be more refined than yours.
 
Abysmal Vapor,

iScrtAznMan

New Member
There are cartridge heater with a probe inside ,like those for rosin plates ;), i suggest you take a look at those,but IMO ,in some builds it would be batter to control the temp based on resistance curve (Check RTD temp sensors). Another great source would be the Bud Toaster thread,now Herb Cube by @Hippie Dickie,he also has custom PID control ,which might be more refined than yours.

Yeah I definitively need to DIY my own heater design. My current design is using an Underdog Log I've had for a few years. After I got a volcano I got irritated at the size and lack of configurability and thought that the log could do the same thing with temp control. I'm not sure how much more refined you can get with writing a PID unless you're talking about getting an optimal tune, but the way I have it set up makes it easy to modify and update the pid settings from my desktop while it's running. But if people are looking for preset, this probably isn't the solution as it will highly depend on your TC, heater, and how well the system can model real world behavior (which in my case is not great currently but it produces results I'm currently ok with).

To give you an idea how easy it is to change settings, this is the snippet of the client code to set PID tunnings. I will just rerun my client code anytime I want to update, but again I want to eventually get this integrated in a webapp so I don't need to even bother with running this. Maybe I'll set it up for cli first. Once the client has sent data, the controller will begin send readings to the last client that it received data from for diagnostic and observation purposes (I'll post a pic of graphs once image attachments are enabled. Don't really like using imgur). It's all over UDP because the client isn't really essential to controller function:
Python:
UDP_IP = (socket.gethostbyname('raspberrypi.local'),12345)
udpClient = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("connecting . . . ")
temp = 210
kp = .11
ki = .003
kd = .04
minR = -100
maxR = 100
data = dict(temp=temp, kp=kp, ki=ki, kd=kd, minR=minR, maxR=maxR)
sentBytesCount = udpClient.sendto(pickle.dumps(data), UDP_IP)
print("new config sent")

the min and max R are to limit Reset windup (the I value). The values depend heavily on the max power of the variable powersupply and how quickly your temp variable can respond to real world changes.

I'm not too sure if an RTD is better, but it's probably not worth integrating an RTD with the current heater. According to Omega, a TC is capable of faster response times, and an integrated grounded thermocouple that you mentioned would be better for reactivity. If there's an RTD that is optimized for open air readings, that would probably be the way to go though. Most of my info comes from Omega though, and it's possible I'm just misinformed. However the extra resolution from an RTD isn't too important, it's more important for the vape to quickly react to temp changes. https://www.omega.com/en-us/resources/rtd-vs-thermocouple. However I do believe the ADC I'm using is too slow and I think by switching to an Arduino for direct analog reads would be much more responsive.

I've seen Hippie Dickie's Herb Cube. He actually chimed in the original thread and gave some good advice. I think his glass heater design is great, it would work well for using the unsheathed Omega TC I spent a bunch of money on and can't use. I think one issue with his design is that he wants to make it commercial, which means you need to make it user friendly for your lowest common denominator. I don't want such a constraint and want to maximize control and expose as many variables as possible that I can change.

Since this vape lives on my desk, it will have access to a local network connection. It doesn't rely on the internet, but does rely on your local network being able to identify the Pi through mDNS. With this, I only really need to control the power supply to turn it on or off and can leave the pi running the vape controller the rest of the time. I may refine this a bit more to ensure the Pi will start the controller when it's on, but for now I can just ssh to it to start it.
 

iScrtAznMan

New Member
This is what I'm watching on my computer monitor in the background. The tuning I have is definitely off, I think I may have changed V but was too lazy to retune. I may look into finding an auto-tune library to simplify, but I want to get a bowl probe first.logexample - Copy.PNG
This is an example of a hit. Just moving the log introduces some disturbance (either the TC is moving/scraping the heater or there's some airflow).loghit - Copy.PNG
You can see the 20C temp spike when I stop hitting. I pack extremely light (I've noticed the most vapor, but a harder pack probably gets you higher) and run through a sneaky pete globe with water in it (with Volcano whip). I want to blame the tuning on how high the spike is, but it's still not great with less aggressive tunes. Maybe the heater has too much thermal mass? Then again when I hit it, it will consistently drop by the same amount which makes me think the TC is reading the passing air temp but it also makes me think the air doesn't reach my target temp since it's still touching the heater. Maybe I should have the actual measurement TC in the bowl and use a TC in the heater as a safety shutoff.

I like to take successive long hits, and this is what it looks like with a pretty aggressive tuning. The slingshot is a bit too excessive (there was less slingshot at lower power. I think this is an issue of too much wattage over too short a distance. There was better response at 30V (1.5A, so 45W) ). This ends up really toasting the top of your bowl (a nice dark brown) when you want lower temps. If you vape at 230+, I can imagine there is significant risk of combustion.
normalusagelog - Copy.PNG


Edit: I was having issues with matplotlib labeling 2 graphs . . . PID output is normalized to a number out of : pwmMax = 2**16-1. Top graph is temperature. Time is in minute:seconds. The seconds are labeled at funny intervals, I need to fix that and make it a bit easier to analyze.
 
Last edited:
iScrtAznMan,
  • Like
Reactions: Cheebsy
Top Bottom