Preparing for release v0.1

Updated Circuit image
renamed directories for better understanding
fixed bugs in pi-slave/main.py
fixed bugs in pi-master/main.py
polished Readme.md
This commit is contained in:
Jonas_Jones 2022-02-21 02:18:46 +01:00
parent af15984091
commit 6a8e2379e9
5 changed files with 339 additions and 223 deletions

57
pi-slave/main.py Normal file
View file

@ -0,0 +1,57 @@
import RPi.GPIO as GPIO
import subprocess
import time
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Powering Status Pin to indicate that control program is up
GPIO.setup(4, GPIO.OUT)
GPIO.output(4, True)
# setting up communication pins for binary fanmode transmission
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
# define default variables -> fan speed will be at max. if someting goes wrong with getting cpu temps
thermal = -99
fanmode = 100
i = 0
# function to get cpu temperature on linux and macOS and decide on fan speed.
def temp(thermal, fanmode):
thermal = int(round(float(subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp", shell=True).rstrip())/1000,2))
if thermal <= 20:
fanmode = 0
elif 20 < thermal <= 40:
fanmode = 25
elif 40 < thermal <= 60:
fanmode = 50
elif 60 < fanmode <= 70:
fanmode = 75
elif 70 < fanmode:
fanmode = 100
return thermal, fanmode
# main loop
while True:
# get cpu temp
thermal, fanmode = temp(thermal, fanmode)
if fanmode == 0 or fanmode == 25:
GPIO.output(17, False)
GPIO.output(18, True)
elif fanmode == 50:
GPIO.output(17, True)
GPIO.output(18, False)
elif fanmode == 75:
GPIO.output(17, True)
GPIO.output(18, True)
else:
GPIO.output(17, False)
GPIO.output(18, False)
# cpu temp will be updated every 5 seconds
time.sleep(5)
i += 1
# log cpu temp and fan speed
print("----- Run Nr.:", i, "\nCpu temperature measured: ", str(thermal) + "°C", "- Fanspeed: ", str(fanmode) + "%")