From 17c4afebfc808f984b15766f29b9e9b0a1d3eefd Mon Sep 17 00:00:00 2001 From: Jim Nicholson Date: Thu, 14 May 2026 12:56:01 -0700 Subject: [PATCH] Fan driver for waveshare board --- autofan.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 autofan.py diff --git a/autofan.py b/autofan.py new file mode 100755 index 0000000..4c6915d --- /dev/null +++ b/autofan.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +import RPi.GPIO as GPIO +import time +import subprocess + +GPIO.setmode(GPIO.BCM) +GPIO.setup(14, GPIO.OUT) + +pwm = GPIO.PWM(14, 100) + +# print("\nPress Ctrl+C to quit \n") + +dc = 0 + +pwm.start(dc) + +try: + while True: + temp = subprocess.getoutput("vcgencmd measure_temp|sed 's/[^0-9.]//g'") + print("CPU Temp: ",float(temp)) + if round(float(temp)) >= 45: + dc = 100 + pwm.ChangeDutyCycle(dc) + time.sleep(180) + + if round(float(temp)) >= 40: + dc = 85 + pwm.ChangeDutyCycle(dc) + time.sleep(120) + else: + dc = 70 + pwm.ChangeDutyCycle(dc) + time.sleep(60) + +except KeyboardInterrupt: + pwm.stop() + GPIO.cleanup() +