Last active
November 22, 2015 17:57
-
-
Save Logic-gate/38f56d86911700dffff7 to your computer and use it in GitHub Desktop.
RPI-PiFace start/stop fan according to temperature(vcgencmd) - Fan Control If the temperature(vcgencmd measure_temp) is =(greater than or equals) 43.0 C', start the fan If the temperature is = 42.9 C', Stop the fan This assumes a 5V or less fan is present.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import re | |
import subprocess | |
import pifacedigitalio as pio | |
import time | |
import datetime | |
def get_temp_from_system(): | |
temp = subprocess.check_output(['vcgencmd', 'measure_temp']) | |
str_temp = str(temp) #important | |
r = re.findall('[0-9]{1}', str_temp) #I am terrible at regex... | |
for_humans = r[0]+r[1]+'.'+r[2] | |
return for_humans | |
def am_i_on(pin): | |
return pd.output_pins[int(pin)].value | |
def run(pin): | |
current_date = datetime.datetime.now() | |
temp = get_temp_from_system() | |
if temp >= '43.0': | |
print(temp+' @ '+str(current_date)) | |
if am_i_on(int(pin)) == 0: | |
print('Fan is Off...Starting Fan') | |
pd.output_pins[int(pin)].value = 1 | |
else: | |
time.sleep(25) | |
print('Fan is ON') | |
elif temp <= '42.9': | |
print(temp+' @ '+str(current_date)) | |
if am_i_on(int(pin)) == 1: | |
print('Fan is on...Shuting it Down') | |
pd.output_pins[int(pin)].value = 0 | |
else: | |
time.sleep(25) #Remove, if you want real-time checking | |
print('Fan is OFF') | |
else: | |
pass | |
pd = pio.PiFaceDigital() | |
while(True): | |
run(5) #Depends on your wiring. Mine was on OUTPUT_PIN-5 and the 5V-OUTPUT_PIN-9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment