This Python script was created for the purpose to control a PWM FAN Noctua NF-A4x20 5V, using Raspberry Pi 4B hardware features.
While the original script uses WiringPi this script rebuilds everything on top of gpiozero.
- To read the FAN speed a DigitalInputDevice is used that counts the falling flanks.
- Depending on the pin that is used for fan PWM control gpiozero uses hardware or software PWM (Hardware PWM is available on pins GPIO12, GPIO13, GPIO18, GPIO19)
- The temperature is directly read from the linux file system
- The input values are then used to update an PID controller
- The output of the PID controller is mapped to the PWM range of the Noctua Fan (20% - 100%)
- Set PWM pin to control the FAN (e.g. GPIO12)
- Set TACHO pin to read FAN speed (e.g. GPIO6)
- The other 2 fan pins can be directly connected to 5V & GND pins
- CPU usage stays between 1% and 3% (if a higher pwm frequency is used it requires more processing power although it shouldn't)
- Noctua white paper - Noctua PWM specifications white paper
git clone https://github.com/katringoogoo/rpi-pwm-fan-control.git
cd rpi-pwm-fan-control
pip3 install -r requirements.txt
./rpi-pwmfan.py
Most of the variables from the script can be overridden via commandline arguments. Have a look at
./rpi-pwmfan.py -h
In order be able to use Hardware PWM make sure that you connected the PWM pin of the fan to a hardware capable pin on the Raspberry Pi.
Next install the pigpio library & daemon:
sudo apt-get install pigpio
sudo systemctl start pigpiod # start the daemon
sudo systemctl enable pigpiod # optional: autostart on startup
and start the script with the following arguments
./rpi-pwmfan.py --use-pigpio
Note: if you want to disable pigpiod again you have to stop the daemon with sudo systemctl stop pigpiod
More information is available on the pigpio website