PWM fans come with 4 wires:
- Power (3.3V, 5V, 12V)
- PWM speed control
Per the GPIO map, there is a convenient header 9J1:
- GPIO (for tach)
On the 40-pin header, there are 5 hardware PWMs we can use per our PWM guide. We do not want to waste CPU cycles to generate inaccurate PWM via software GPIO bitbanging.
We can hook these up to the fan via female to male jumper wires.
- pwm-a - Pin 33
- pwm-ao-a - Pin 11
- pwm-ao-b-6 - Pin 12
- pwm-ao-b-9 - Pin 13
- pwm-e - Pin 32
- pwm-f - Pin 35
To test with PWM A on pin 33:
sudo ldto enable pwm-a sudo ldto enable pwm-a-fan
This will create a hwmon device in
The fan speed can be read from the file
fan1_input in the hwmon device directory:
The pwm level (0-255) can be set by the file
pwm1 in the hwmon device directory.
echo 0 | sudo tee pwm1
To make it permanent:
sudo ldto merge pwm-a sudo ldto merge pwm-a-fan
From here, you can write userspace software in any language to implement control systems by reading fan1_input and writing to pwm1.
Most users prefer to link fan speed to SoC temperatures. To enable temperature-based fan speed control, run the previous merge commands and then add:
sudo ldto merge pwm-a-fan-auto
After rebooting, fan speed should be directly controlled by SoC temperatures. This profile deactivates the fan < 50C and peaks at 60C for maintaining maximum performance.