diff options
author | Matt Kohls <mattkohls13@gmail.com> | 2018-06-17 16:03:00 -0400 |
---|---|---|
committer | Matt Kohls <mattkohls13@gmail.com> | 2018-06-17 16:03:00 -0400 |
commit | dd45d017cf6d256acafccf17953b26d2ffaa0cb6 (patch) | |
tree | ffd7c79ce02a6b4f4a2922683922aaa936b275b2 /rpi-temp-control.py | |
parent | 60ead3fadb1bac2e79b54be885bf1b3a15674b1e (diff) | |
download | rpi-temp-control-dd45d017cf6d256acafccf17953b26d2ffaa0cb6.tar.gz rpi-temp-control-dd45d017cf6d256acafccf17953b26d2ffaa0cb6.tar.bz2 rpi-temp-control-dd45d017cf6d256acafccf17953b26d2ffaa0cb6.zip |
Adding in comments and reworking how temp is read from CPU
Diffstat (limited to 'rpi-temp-control.py')
-rw-r--r-- | rpi-temp-control.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/rpi-temp-control.py b/rpi-temp-control.py index d99824a..fb7f0aa 100644 --- a/rpi-temp-control.py +++ b/rpi-temp-control.py @@ -3,11 +3,14 @@ ## # rpi-temp-control # -# +# Changes speed of system fan to try and control the CPU/GPU temperature. This is done through the use of a PID loop +# that is targeting a specific temperature. # # Matt Kohls +# 2018 +# +# Licensed under GPL v3 -import subprocess from gpiozero import Motor from pid import PID from time import sleep @@ -22,14 +25,10 @@ MIN_FAN_SPEED = 80 / 100 # # @return temperature of GPU/CPU def grab_temp(): - try: - file = open("/sys/class/thermal/thermal_zone0/temp", "r") + val = 0 + with open("/sys/class/thermal/thermal_zone0/temp", "r") as file: val = int(file.readline()) / 1000 - file.close() - return val - except: - print("Error reading from thermal zone") - return 0 + return val # Initial loop setup ploop = PID(1, 1, .02, Integrator_max=100, Integrator_min=0, Set_Point=TEMP_TARGET) @@ -42,9 +41,8 @@ last_temp = 0 while True: sleep(1) temp = grab_temp() - print(temp) - cycle_change = (ploop.update(temp)) * -1 - cycle = (100 + int(cycle_change)) / 100 # Since fan.forward() wants a number between 0 and 1 + cycle_change = ploop.update(temp) + cycle = (100 - int(cycle_change)) / 100 # Since fan.forward() wants a number between 0 and 1 if cycle <= .2: cycle = 0 |