Guest User

Untitled

a guest
Jun 7th, 2016
264
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import RPi.GPIO as GPIO
  3. import time
  4. import os
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. GPIO.setwarnings(False)
  8.  
  9. IMPULS_PIN = 23 #Pin, der zum Transistor fuehrt
  10. SLEEP_TIME = 30 #Alle wie viel Sekunden die Temperatur ueberprueft wird
  11. MAX_CPU_TEMP = 40 #Ab welcher CPU Temperatur der Luefter sich drehen soll
  12. MAX_SENSOR_TEMP = 30 #Ab welcher Temperatur im Gehaeuse der Luefter sich drehen soll
  13. SENSOR_ID = '' #ID des Sonsors, BITTE ANPASSEN, falls kein Sensor vorhanden leer lassen
  14.  
  15.  
  16.  
  17. def get_sensor_temperature():
  18. try:
  19. tempfile = open("/sys/bus/w1/devices/"+SENSOR_ID+"/w1_slave")
  20. text = tempfile.read()
  21. tempfile.close()
  22. temperature_data = text.split()[-1]
  23. temperature = float(temperature_data[2:])
  24. temperature = temperature / 1000
  25. return float(temperature)
  26. except:
  27. return 0
  28.  
  29. def get_cpu_temperature():
  30. temp = os.popen('vcgencmd measure_temp').readline()
  31. return float(temp.replace("temp=","").replace("'C\n",""))
  32.  
  33.  
  34.  
  35. def main():
  36.  
  37. #Init
  38. GPIO.setup(IMPULS_PIN, GPIO.OUT)
  39. GPIO.output(IMPULS_PIN, False)
  40.  
  41. while True:
  42. cpu_temp = get_cpu_temperature()
  43. sensor_temp = get_sensor_temperature()
  44. if cpu_temp >= MAX_CPU_TEMP or sensor_temp >= MAX_SENSOR_TEMP :
  45. GPIO.output(IMPULS_PIN, True)
  46. else:
  47. GPIO.output(IMPULS_PIN, False)
  48.  
  49. #print "gemessene CPU Temperatur:" + str(cpu_temp)
  50. #print "gemessene Sensor Temperatur:" + str(sensor_temp)
  51.  
  52. time.sleep(SLEEP_TIME)
  53.  
  54.  
  55. if __name__ == '__main__':
  56. main()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×