hinzufügen der fehlenden dateien
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Name: cooler_skript
|
||||
# Purpose: Anschluss eines Kuehlkoerpers und Temperatur Sensor
|
||||
# GPIO-Library: RPi.GPIO 0.5.4
|
||||
#
|
||||
# Author: Felix Stern
|
||||
# Website: www.tutorials-raspberrypi.de
|
||||
#
|
||||
# Created: 04.04.2014
|
||||
#-------------------------------------------------------------------------------
|
||||
#!/usr/bin/env python
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import os
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
IMPULS_PIN = 23 #Pin, der zum Transistor fuehrt
|
||||
SLEEP_TIME = 30 #Alle wie viel Sekunden die Temperatur ueberprueft wird
|
||||
MAX_CPU_TEMP = 40 #Ab welcher CPU Temperatur der Luefter sich drehen soll
|
||||
MAX_SENSOR_TEMP = 30 #Ab welcher Temperatur im Gehaeuse der Luefter sich drehen soll
|
||||
SENSOR_ID = '' #ID des Sonsors, BITTE ANPASSEN, falls kein Sensor vorhanden leer lassen
|
||||
|
||||
|
||||
|
||||
def get_sensor_temperature():
|
||||
try:
|
||||
tempfile = open("/sys/bus/w1/devices/"+SENSOR_ID+"/w1_slave")
|
||||
text = tempfile.read()
|
||||
tempfile.close()
|
||||
temperature_data = text.split()[-1]
|
||||
temperature = float(temperature_data[2:])
|
||||
temperature = temperature / 1000
|
||||
return float(temperature)
|
||||
except:
|
||||
return 0
|
||||
|
||||
def get_cpu_temperature():
|
||||
temp = os.popen('vcgencmd measure_temp').readline()
|
||||
return float(temp.replace("temp=","").replace("'C\n",""))
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
#Init
|
||||
GPIO.setup(IMPULS_PIN, GPIO.OUT)
|
||||
GPIO.output(IMPULS_PIN, False)
|
||||
|
||||
while True:
|
||||
cpu_temp = get_cpu_temperature()
|
||||
sensor_temp = get_sensor_temperature()
|
||||
if cpu_temp >= MAX_CPU_TEMP or sensor_temp >= MAX_SENSOR_TEMP :
|
||||
GPIO.output(IMPULS_PIN, True)
|
||||
else:
|
||||
GPIO.output(IMPULS_PIN, False)
|
||||
|
||||
#print "gemessene CPU Temperatur:" + str(cpu_temp)
|
||||
#print "gemessene Sensor Temperatur:" + str(sensor_temp)
|
||||
|
||||
time.sleep(SLEEP_TIME)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user