Automatically set fan's PWM based on CPU Temperature for a Raspberry Pi. This script will work only if you have the fan connected to RPi via a GPIO pin.
I bought a Raspberry Pi 4 with official case and official fan and the fan is very noisy.
The RPi is on my desk and this one is next to my bed and it was disturbing.
I am not exaggerating but the RPi official fan is noisier than my Desktop PC with 7 fans in it so I had to do something.
sudo pip3 install -r requirements.txt
or
sudo pip3 install gpiozero
sudo cp fancontroller.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable fancontroller.service
sudo systemctl start fancontroller.service
sudo systemctl status fancontroller.service
TEMPS
and PWM_OUTPUT
: Edit them based on your temperature limit and what PWM you want to use when the CPU Temperature is above the limit you selected previous.
GPIO_PIN
: Edit this one based on the GPIO Pin you are using for your fan. The script I think it can be extended with more fans, example below.
DEFAULT_PWM
: Put the fan PWM value back to default value when you stop the script.
Extend script for more fans(I didn't test this one bcs I don't have more fans, so it might be broken):
fan1 = PWMOutputDevice(GPIO_PIN1)
fan2 = PWMOutputDevice(GPIO_PIN2)
fan3 = PWMOutputDevice(GPIO_PIN3)
fan1.value = 1.0
fan2.value = 0.8
fan3.value = 0.4
sudo apt install stress
sudo pip3 install stressberry
sudo /home/<<USER>>/.local/bin/stressberry-run -n "Custom PWM Test" -d 1800 -i 300 -c 4 test.out
sudo MPLBACKEND=Agg /home/<<USER>>/.local/bin/stressberry-plot test.out -f -d 300 -f -l 400 1600 -t 30 90 -o test.png --not-transparent