Fan Controller plugin?

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.

Yes, is this possible, or does it already exist?

Yes it is there you can buy it
Raspberry Pi 4 Case Fan - Koel je Raspberry Pi

https://www.jeffgeerling.com/blog/2020/raspberry-pi-4-has-fan-now-case-fan

A plugin to control the fan depending on temperature of the cpu.

// Hardware PWM Controller for the Raspberry Pi 4 Case Fan · GitHub

Ps. If there was a plugin you could find it in the store.

I’m not running Pi OS, but Volumio OS.

the base of volumio is Pi OS Buster

But if I install it, how do I remove it? One had problem the fan ran at full speed all the time. Anyway to access the Buster OS GUI on Volumio OS?

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.

Ice cooler low profile wil give you a great result.around 38c with any ambient.

image

1 Like
  1. enable SSH in Volumio Dev mode

  2. Start putty → Volumio Login in SSH mode

  3. Login with name and password

  4. sudo apt update && sudo apt autoremove -y && sudo apt clean

  5. sudo apt install python3-rpi.gpio python3 cron

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

… and at the end

sudo reboot
1 Like

in your line 4. doing a apt upgrade will brick your volumio
so don’t add that.

best regards,
dvo

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

thanks to all

try:

cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb

Thanks. Nothing changes (after a reboot, next) :frowning:

The see if you can use it in a 3 wire connection,
Black = GND
RED = 5V
Yellow = GPIO4

Add the following line to /boot/userconfig.txt
dtoverlay=gpio-fan,gpiopin=4,temp=60000

No need for a script.

Thanks, edited. Nothing seems changed, to my ears. How can I test it?

cd ~
nano temp.sh

Paste:

while true
do
	echo $(vcgencmd measure_temp)
	sleep 5
done

Press:
CTRL+o => Enter => CTRL+x

chmod 777 temp.sh

sudo bash  temp.sh
temp=25.3'C
temp=24.8'C
temp=25.3'C
temp=25.8'C
temp=25.3'C
temp=25.3'C
temp=25.8'C
temp=26.7'C
temp=26.2'C
temp=24.8'C
temp=25.8'C
temp=26.7'C
temp=26.2'C
temp=26.7'C
temp=25.8'C
temp=26.7'C
temp=26.2'C
temp=25.8'C
temp=26.7'C

Fan will turn on at 60degC and off at 50degC