Unsolved Script to turn off cooler
-
-
@ian57 This idea is great, but I use the other ports for usb controllers, xbox360 receiver and are on the front of SNES
If I soldered the wires at the voltage points of the USB, would it have problem when plugging a controller or a usb key? If it does not give you trouble, I do it even easier for me.
If I do not have to follow the script of @lackyluuk, I just did not understand there in the diagram the why of having a transistor, for safety?
-
@azvarel; the transitor is for switch and safety. I don't think that standard GPIO can supply enough power to run your fan correctly. So we use the +5V directly from the power supply to power the fan, and the GPIO + transitor are making the script controllable switch.
Soldering to get only the power supply is a bit risky for the plugged element I think. A fan, is a motor, and it can have bad effects on it's power circuit. And the usb deliver at max 500mA. If you try to do that .. not on an usb key slot... try it on the usb snes controller slots... it uses less current ...
If someone elsehas an idea about that?
-
@ian57 so we went back to the script.
-
-
@azvarel @Substring just add a time.sleep(1) or (2) into the while() loop
-
Well, maybe i say a stupidity but with a thermal switch? It avoids the question of the script and you can choose one with a temperature of closing and opening of your choice.
-
@tikiandskull nothing is stupid, any idea is valid, where would you find this thermal switch?
-
-
#!/usr/bin/env python3
import os
from time import sleep
import signal
import sys
import RPi.GPIO as GPIOpin = 27 # The pin ID, edit here to change it
maxTMP = 50 # The maximum temperature in Celsius after which we trigger the fan
sleepTime = 30 # The time to sleep between temp checksdef setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.setwarnings(False)
return()def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
temp =(res.replace("temp=","").replace("'C\n",""))
print("temp is {0}".format(temp)) #Uncomment here for testing
return tempdef fanON():
print("Fan on ...")
setPin(True)
return()def fanOFF():
print("Fan off ...")
setPin(False)
return()def getTEMP():
CPU_temp = float(getCPUtemperature())
if CPU_temp > maxTMP:
fanON()
sleep(sleepTime) # Sleep additional time in order to ensure that we stay below max temp ...
else:
fanOFF()
return()def setPin(mode): # A little redundant function but useful if you want to add logging
GPIO.output(pin, mode)
return()try:
setup()
while True:
getTEMP()
sleep(sleepTime) # Read the temperature every x amount of seconds ...
except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt
GPIO.cleanup() # resets all GPIO ports used by this script -
With this transistor 2N4401 600 mA, 40V and 5v fan Works perfectly.
-
@Pdagarcia where would you put this script?
-
@azvarel I would place the script into
/recalbox/scripts
and call the script as a background process from the startup directory/etc/init.d
for example asS32StartFanControl
This could look like this (just one proposal, you can do it however you like it):#!/usr/bin/python import subprocess try: subprocess.Popen(["python","/recalbox/scripts/fanControl.py"]) except KeyboardInterrupt: print "Quit"
I have called my script that I start as
fanControl.py
-
@lackyluuk thanks
-
@azvarel I'm with the same problem, did you work? which method did you use?