If a fan controller plugin exists I haven’t been able to find it. I thought I’d ask before trying to write one.
It should be easy to set up a python script as a service to control the fan via GPIO, but for the life of me I can’t get vcgencmd on Volumio to work without sudo. That and it would seem more future proof to use a plugin as it can be backed up and reinstalled on Volumio easier.
vcgencmd measure_temp shows 69 degrees C after a while of power on, ambient temperature is 23 degree C, RPi4 sits in a plastic case with a couple of openings, has heat sinks on chips. I should have bought one of those aluminium cases which mounts direct on the chips. Sits above a class AB amp.
Test temperature controller: vcgencmd measure_temp
Python3 starten sudo python3
Start fan
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT)
GPIO.output(14, True)
Stop fan
GPIO.output(14, False)
leave python3
exit()
create new directory and navigate to it
cd /home
sudo mkdir /home/fan
cd /home/fan
create script in the new created directory
sudo nano fancontrol.py
Script
#!/usr/bin/python3
import os
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT)
#read out temperature with vcgencmd and return it as text
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
#read Temp and convert to a float
temp_float = float(getCPUtemperature())
try:
#Temp > 60, fan on
if (temp_float > 60):
print (temp_float)
print ("power on fan...")
#fan on
GPIO.output(14, True)
#run fan for 180 sec.
time.sleep(180)
print ("power off fan...")
#fan off
GPIO.output(14, False)
print (float(getCPUtemperature())
else:
print (temp_float)
print ("temp too low")
#if program is aborted, then fan off
except KeyboardInterrupt:
print (float(getCPUtemperature())
print ("power off fan...")
GPIO.output(14, False)
print ("cancelling...")
save script and exit editor
ctrl+s
ctrl+x
make script executable
sudo chmod +x fancontrol.py
start script
sudo python fancontrol.py
or
/home/fan/fancontrol.py
Start script automatically every 5 minutes
sudo crontab -e
write the following into the file
# starting the fan every minute
*/5 * * * * /home/fan/fancontrol.py
thanks defr0ke! I’ve used your script and now my Rpi4 with volumio is cool and silent…
just a note: I got error on every print instructions, so I removed since I don’t need any feedback.
Hi to all, I’m new in community and a Volumio user from some months on a RPi4.
I’d control a Nuctua fan (5V PWM), already modified to be connected to the 4 RPi4 pins. Thanks for your works and thanks to @defr0ke for the Python script.
My Volumio version is 3.785.
I’ve tried to launch the script but it seems that the import of RPi.GPIO (inexplicably) fails. Nevertheless with apt-get it seems updated to the newest version.
I do not use -get upgrade. I’ve tried to reboot but nothing: the fan continues to rotate at max RPM all the time (and launching the py script the lib import fails, as said).
…what can I do? ._. without reinstall the whole os, possibly :S