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 upgrade -y && 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

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

best regards,
dvo