Raspberry Pi 5 上的风扇速度控制在 Ubuntu 23.10 中不起作用

Raspberry Pi 5 上的风扇速度控制在 Ubuntu 23.10 中不起作用

在 Raspberry Pi 5 上运行 Ubuntu 23.10 时,风扇速度控制似乎不起作用。风扇始终以接近最大速度运行,并且无论 CPU 温度如何,cur_state输入/sys/class/thermal/cooling_device0/都会停留在 的值4。我怀疑这与 Raspberry Pi OS 上报告的此故障有关:https://forums.raspberrypi.com/viewtopic.php?t=356881

还有其他人成功做到这一点吗?

答案1

此问题已作为内核更新的一部分得到修复。

您可以使用以下命令更新您的 Ubuntu Server 安装:

sudo apt update
sudo apt upgrade

重新启动后,风扇速度将按预期运行。

答案2

现在 ppa:waveform/fan-fix 中有一个内核构建补丁 (https://launchpad.net/~waveform/+archive/ubuntu/fan-fix) 应作为临时修复,直到下一个内核版本发布。这允许风扇速度控制工作,但有人担心滞后被忽略,因此这可能不是最终的修复。

答案3

这很烦人,我一直在做的只是交换值,直到我们得到一个新的稳定内核:

sudo bash
cat > /sys/class/thermal/cooling_device0/cur_state
2
<CTRL-D>

答案4

我也对此感到烦恼,决定让 Python 完成所有工作。请随意使用https://pastebin.com/SbFb4LYE

from subprocess import run as srun, PIPE
from time import sleep
from datetime import timedelta as td, datetime as dt
 
## Use step values to activate desired FAN value
STEP1 = 48
STEP2 = 60
STEP3 = 65
STEP4 = 72
 
SLEEP_TIMER = 1
 
TICKS = 3
DELTA_TEMP = 3
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
fanControlFile = '/sys/class/thermal/cooling_device0/cur_state'
 
def main():
    print("Running FAN control for RPI5 Ubuntu")
    t0 = dt.now()
 
    command = f'tee -a {fanControlFile} > /dev/null'
    oldSpeed = 0
    ticks = 0
 
    speed = 1
    lastTemp = 0
 
    while True:
        sleep(SLEEP_TIMER) # force 1 second timer, just to reduce polling calls
        t1 = dt.now()
        if(t1 + td(minutes=TICKS) > t0):
            t0 = t1
            
            tempOut = getOutput('vcgencmd measure_temp')
            try:
                cels = int(tempOut.split('temp=')[1][:2])
            except:
                cels = 40
 
            if STEP1 < cels < STEP2:
                speed = 1
            elif STEP2 < cels < STEP3:
                speed = 2
            elif STEP3 < cels < STEP4:
                speed = 3
            elif cels >= STEP4:
                speed = 4
 
            deltaTempNeg = lastTemp - DELTA_TEMP
            deltaTempPos = lastTemp + DELTA_TEMP
 
            if oldSpeed != speed and not(deltaTempNeg <= cels <= deltaTempPos):
                print(f'oldSpeed: {oldSpeed} | newSpeed: {speed}')
                print(f'{deltaTempNeg}ºC <= {cels}ºC <= {deltaTempPos}ºC')
                print(f'{"#"*30}\n' +
                    f'Updating fan speed!\t{t0.strftime(DATETIME_FORMAT)}\n' +
                    f'CPU TEMP: {cels}ºC\n' +
                    f'FAN speed will be set to: {speed}\n' +
                    f'{"#"*30}\n')
                
                _command = f'echo {speed} | sudo {command}'
                callShell(_command, debug=True)
                checkVal = getOutput(f'cat {fanControlFile}')
                print(f'Confirm FAN set to speed: {checkVal}')
                
                oldSpeed = speed
                lastTemp = cels
                ticks = 0
            
            # Log minor details
            ticks += 1
            if(ticks > TICKS * 3):
                ticks = 0
                print(f'Current Temp is: {cels}ºC\t{t0.strftime(DATETIME_FORMAT)}')
    
def callShell(cmd, shell=True, debug=False):
    if debug:
        print(f'Calling: [{cmd}]')
    return srun(f'''{cmd}''', stdout=PIPE, shell=shell)
 
def getOutput(cmd, shell=True):
    stdout = callShell(cmd, shell=shell).stdout
 
    try:
        stdout = stdout.decode('utf-8')
    except:
        pass
 
    return stdout
 
## RUN SCRIPT
main()

相关内容