@PenPen: I am sorry for this way too late answer. Not sure if you need an answer anymore
Here is an example with GPIO pin 14 for controlling the fan. The indents might not be correct
I had a little trouble with copy/paste the code 
Hope I can help you with this
| |
| |
| import os |
| import time |
| import RPi.GPIO as GPIO |
| |
| GPIO.setwarnings(False) |
| GPIO.setmode(GPIO.BCM) |
| |
| TEMP_MAX = 67 |
| ON_TIME = 200 |
| |
| GATE = 14 |
| |
| GPIO.setup(GATE, GPIO.OUT) |
| GPIO.output(GATE, False) |
| |
| def getCPUtemperature(): |
| res = os.popen('vcgencmd measure_temp').readline() |
| return(res.replace("temp=","").replace("'C\n","")) |
| |
| while True: |
| |
| temp_float = float(getCPUtemperature()) |
| |
| try: |
| if (temp_float > TEMP_MAX): |
| |
| GPIO.output(GATE, True) |
| time.sleep(ON_TIME) |
| |
| GPIO.output(GATE, False) |
| else: |
| GPIO.output(GATE, False) |
| |
| except KeyboardInterrupt: |
| print float(getCPUtemperature()) |
| print "power off fan..." |
| GPIO.output(GATE, False) |
| print "cancelling..." |
Forgot to attach a short drawing. I used the official RaspberryPI 5V DC fan.
