Advertisement
zefie

raspi cpufancontrol

Oct 21st, 2014
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/python2.7 -u
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. import subprocess
  6. import sys
  7.  
  8. fanstatus = "Off"
  9.  
  10. # Use GPIO 18
  11. GPIO.setmode(GPIO.BCM)
  12. GPIO.setwarnings(False)
  13. GPIO.setup(18,GPIO.OUT)
  14.  
  15. # Infinite Loop
  16. while True:
  17.     # Get the RasPi's CPU Temp
  18.     temp = subprocess.Popen(["/usr/local/bin/cputemp","temp"], stdout=subprocess.PIPE).communicate()[0].replace("C\n","")
  19.     # Default to verbose
  20.     service = False
  21.  
  22.     # Start to cool at 43C
  23.     if float(temp) > 43.0 and fanstatus == "Off":
  24.         fanstatus = "On"
  25.         GPIO.output(18,GPIO.HIGH)
  26.    
  27.     # Cool until we reach 38C
  28.     if float(temp) < 38.0 and fanstatus == "On":
  29.         fanstatus = "Off"
  30.         GPIO.output(18,GPIO.LOW)
  31.  
  32.     # Be silent if we are starting at boot
  33.     for arg in sys.argv:
  34.         if arg == "service":
  35.             service = True
  36.  
  37.     if service == False:
  38.         # Get the current date
  39.         date = subprocess.Popen(["/bin/date"], stdout=subprocess.PIPE).communicate()[0].replace("\n","")
  40.         sys.stdout.write('\rTemp: '+temp+'C, Fan: '+fanstatus+' (at '+date+')      \b\b\b\b\b\b')
  41.  
  42.     # Sleep for a bit so we aren't a cpu hog
  43.     time.sleep(6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement