I have a Raspberry pi Model B revision 2 and I've set up a mini 5v fan on a relay switch which i want to control with python now. I will be running a crontab every hour to check the temperature of the pi and if the temperature is above 50C i will be running the fan for like 10 min. This is my current setup:
The relay is connected like this diagram here:
I've setup the relay this way, because it has a light on top of it (a red light) which i want it to be on when the fan is working...and off when its not.
Here is my script:
#!/usr/bin/python3
import time
import os
import sys
import RPi.GPIO as GPIO
# Identify which pin controls the relay
FAN_PIN = 3
# Temperature check. Start fan after 50C, Shut down under 50C
FAN_START = 50
def GPIOsetup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(FAN_PIN, GPIO.OUT)
GPIO.setwarnings(False)
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
def fanON():
GPIO.output(FAN_PIN, 0)
print "fan on"
return()
def fanOFF():
GPIO.output(FAN_PIN, 1)
print "fan off"
return()
def getTEMP():
CPU_temp = float(getCPUtemperature())
if CPU_temp>FAN_START:
fanON()
else:
fanOFF()
return()
def main():
GPIOsetup()
getTEMP()
try:
main()
finally:
print ("Finish")
#GPIO.cleanup()
Now the problem is that i am getting some warnings which i just cant get rid off:
root@raspberrypi:/home/pi# python fan.py
fan.py:14: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(FAN_PIN, GPIO.OUT)
fan.py:14: RuntimeWarning: A physical pull up resistor is fitted on this channel!
GPIO.setup(FAN_PIN, GPIO.OUT)
fan off
Finish
The line in question as you can see is this:
GPIO.setup(FAN_PIN, GPIO.OUT)
Why am I getting this error ? i have GPIO.setwarnings(False) in my code. And also should i be using that pin for controlling the relay ? Is there optional pin i should be using ? Thanks.