I would like to PID control the temperature of a water bath using a RaspberryPi4, a solid state relay (SSR) and a heater (200W, 230VAC) using python.
The IVMech library seems a good starting point. As well as Simple-PID
I went for IVMech since I saw it quoted in other projects. I can control my actuator by pulling my SSR low over one of the RPI-GPIO pins.
Currently, I'm stuck with reducing the test_pid.py test code to the bare minimum required. Please see my code sample below. Is it fine to just use the output of the PID calculation as the time to turn the heating element on?
In my case I don't want to powercycle so many times (sampletime around 1-2s) since my application should last > 1year and I'm not sure if the SSR that uses a photodiode to for galvanic isolation can be cycled indefinitely. I read that the SSR supports around 100MIO cycles. For a switching frequency of 1Hz that would correspond to a lifetime of around 3years.
import PID
import time
import numpy as np
from scipy.interpolate import BSpline, make_interp_spline # Switched to BSpline
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
HEATER = 17
GPIO.setup(HEATER,GPIO.OUT)
P = 0.2
I = 0.0
D = 0.0
L = 0
sampletime = 2.0
def measure_Temp:
temp = 20.0
return temp
while True:
pid = PID.PID(P, I, D)
pid.SetPoint=25.0
pid.setSampleTime(sampletime)
END = L
feedback = measure_Temp()
pid.update(feedback)
output = pid.output
GPIO.output(HEATER, False)
time.sleep(output)
GPIO.output(HEATER, True)