PWM fans come with 4 wires:
- Ground
- Power (3.3V, 5V, 12V)
- Tachometer
- PWM speed control
Per the GPIO map, there is a convenient header 9J1:
- Ground
- GPIO (for tach)
- 5V
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 /sys/class/hwmon/
.
The fan speed can be read from the file fan1_input
in the hwmon device directory: cat fan1_input
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.