RPI4 PWM fan control
After several years of using regular cases for my rpi4, i came to the point of being super annoyed by the fan noise.
So I've decided to buy a PWM fan that would only spin with a ratio based on the current temperature of the CPU. In principle, since my pi is mostly idling, I should then never hear the fan in my living room.
After scrolling a bit in AliExpress, I picked the 52pi Ice Tower Cpu cooling fan.
After receiving the product, I knew it wouldn't just work miraculously after wiring it up. So I started looking for a solution to control the PWM from my Librelec distribution and found these:
The first project does not require a PWM fan. You can use it with a basic 5V fan but you'll need a transistor to adjust the fan speed. That's not what I am looking for but it was a good place to get started since the tutorial is well-written, especially for the creation of a service that will run automatically when the pi boots.
The second project assumes that you're controlling a PWM fan and lets you define the PWM pin (`FAN_PIN`). Perfect !
Note: With Librelec, you'll need the install the pi tools add-on
Addons --> install from repository --> LibreELEC Add-ons --> Program Addons --> Raspberry PiTools
- First, let's set the
FAN_PIN
in the script. I've wired the PWM wire of my fan (blue) to TXD (GPIO 14). Be careful, the scripts sets the configuration mode toBOARD
which means that putting14
won't work. You should use the pin number instead which is8
here:
FAN_PIN = 8 ### RaspberryPi GPIO PI used to drive PWM pin of Fan
ssh
into your pi and create a folder for the python script
> ssh root@<ip>
...
> mkdir .kodi/userdata/PWM_fan
> exit
- Now transfer the python script to your rpi
> scp C:\Users\cemni\Downloads\libreelec_pwm_fancontol.py root@<ip>:~/storage/.kodi/userdata/PWM_fan/PWM_fan.py
- Transfer the service file as well
> scp C:\Users\cemni\Downloada\PWM_fan.service root@<ip>:~/.config/system.d/PWM_fan.service
- Configure the service to start with the pi
> ssh root@<ip>
...
> chmod 755 .config/system.d/PWM_fan.service
> systemctl enable PWM_fan
> systemctl start PWM_fan
> exit
- Tune the script parameters
This is the most time-consuming part. The default parameters of the script were not satisfying because the fan had a high pitch sound, worst than my original setup ! So i changedPWM_FREQ
until finding a solution that is quiet enough.PWM_FREQ = 23
worked for me but it could be different if you're using another type of fan.
An that's it ! My rpi is now dead silent and I can finally chill in my living room while reading a book.