Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

CP - PID controller for reflow hot-plate
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CP - PID controller for reflow hot-plate

by slight on Mon Nov 22, 2021 8:24 pm

Hello community,
is there anywhere out there a example of how to implement / what library to use for PID controller applications in CircuitPython?
i want to try to create a reflow soldering hot-plate controller :-)

i did not find any PID example in the learn search..

my next try would be the simple-pid library - as it is written in pure python and has no external dependencies..

please let me know all ideas / tips you have :-)

sunny greetings
stefan

slight
 
Posts: 43
Joined: Wed Sep 12, 2012 2:23 am

Re: CP - PID controller for reflow hot-plate

by mikeysklar on Wed Nov 24, 2021 12:37 pm

stefan,

Because CircuitPython / MicroPython and Python are all so close if you can find an example in one it probably can easily be moved to another. Take a look at this simple micropython PID library.

https://github.com/B3AU/micropython/blob/master/PID.py

Code: Select all | TOGGLE FULL SIZE
__author__ = 'beau'
import pyb
class PID:
    """
    Discrete PID control
    """

    def __init__(self,input_fun,output_fun, P=3., I=0.01, D=0.0):

        self.Kp=P
        self.Ki=I
        self.Kd=D

        self.I_value = 0
        self.P_value = 0
        self.D_value = 0

        self.I_max=100.0
        self.I_min=0

        self.set_point=0.0

        self.prev_value = 0

        self.output = 0

        self.output_fun = output_fun
        self.input_fun = input_fun

        self.last_update_time = pyb.millis()


    def update(self):

        if pyb.millis()-self.last_update_time > 500:
            """
            Calculate PID output value for given reference input and feedback
            """
            current_value = self.input_fun()
            self.error = self.set_point - current_value
            print ('temp '+str(current_value))
            print ('SP'+str(self.set_point))

            self.P_value = self.Kp * self.error
            self.D_value = self.Kd * ( current_value-self.prev_value)


            lapsed_time = pyb.millis()-self.last_update_time
            lapsed_time/=1000. #convert to seconds
            self.last_update_time = pyb.millis()





            self.I_value += self.error * self.Ki

            if self.I_value > self.I_max:
                self.I_value = self.I_max
            elif self.I_value < self.I_min:
                self.I_value = self.I_min

            self.output = self.P_value + self.I_value - self.D_value

            if self.output<0:
                self.output = 0.0
            if self.output>100:
                self.output = 100.0

            print("Setpoint: "+str(self.set_point))
            print("P: "+str(self.P_value))
            print("I: "+str(self.I_value))
            print("Output: "+str(self.output))
            print ()

            self.output_fun(self.output/100.0)

            self.last_update_time=pyb.millis()

mikeysklar
 
Posts: 6242
Joined: Mon Aug 01, 2016 8:10 pm

Re: CP - PID controller for reflow hot-plate

by adafruit2 on Tue Nov 30, 2021 10:17 pm

tbh hot plates are so slow you dont need PID - just heat to 220-240 *C then turn off the heat. :)
https://learn.adafruit.com/ez-make-oven

adafruit2
Site Admin
 
Posts: 20358
Joined: Fri Mar 11, 2005 7:36 pm

Re: CP - PID controller for reflow hot-plate

by slight on Wed Dec 01, 2021 7:00 am

thanks @adafruit2!
that is a very useful recourse... ;-)
seems i only have to port it to my PyBadge (my main controller)
and see what happens...

i have some ceramic heating elements - i think they could be way faster than normal hotplates...

i will let you know!

sunny greetings
stefan

slight
 
Posts: 43
Joined: Wed Sep 12, 2012 2:23 am

Please be positive and constructive with your questions and comments.