Last active
March 7, 2020 17:26
-
-
Save j4velin/63d3c30208cdb4ab32a3a0d646aa97a2 to your computer and use it in GitHub Desktop.
Temperature based fan control script for Raspberry Pi 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import subprocess | |
import time | |
import re | |
from gpiozero import LED | |
PIN = LED(17) | |
MAX_TEMP = 50 | |
MIN_TEMP = 45 | |
PATTERN = "^temp=([0-9.]*)'C$" | |
def getTemp(): | |
result = subprocess.check_output(["sudo", "vcgencmd", "measure_temp"]) | |
match = re.search(PATTERN, result) | |
return float(match.group(1)) | |
while(True): | |
temperature = getTemp() | |
if temperature >= MAX_TEMP: | |
PIN.on() | |
elif temperature <= MIN_TEMP: | |
PIN.off() | |
#print str(temperature) + " -> " + str(PIN.is_lit) | |
time.sleep(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment