Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO fan control script #444

Merged
merged 3 commits into from Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions image/fancontrol.py
@@ -0,0 +1,34 @@
#!/usr/bin/python
# @Author Ryan Dewsbury (helno)
#
# This script throttles a fan based on CPU temperature.
#
# It expects a fan that's externally powered, and uses GPIO pin 11 for control.

import RPi.GPIO as GPIO
import time
import os

# Return CPU temperature as float
def getCPUtemp():
cTemp = os.popen('vcgencmd measure_temp').readline()
return float(cTemp.replace("temp=","").replace("'C\n",""))

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setwarnings(False)
p=GPIO.PWM(11,1000)
PWM = 50

while True:

CPU_temp = getCPUtemp()
if CPU_temp > 40.5:
PWM = min(max(PWM + 1, 0), 100)
p.start(PWM)
elif CPU_temp < 39.5:
PWM = min(max(PWM - 1, 0), 100)
p.start(PWM)
time.sleep(5)

GPIO.cleanup()
3 changes: 3 additions & 0 deletions image/mkimg.sh
Expand Up @@ -53,6 +53,9 @@ cp -f interfaces mnt/etc/network/interfaces
#custom hostapd start script
cp stratux-wifi.sh mnt/usr/sbin/
chmod 755 mnt/usr/sbin/stratux-wifi.sh
#fan/temp control script
cp fancontrol.py mnt/root/
chmod 755 mnt/root/fancontrol.py

#isc-dhcp-server config
cp -f isc-dhcp-server mnt/etc/default/isc-dhcp-server
Expand Down