PWM fans come with 4 wires:
- Ground
- Power (3.3V, 5V, 12V)
- Tachometer
- PWM speed control
Per the GPIO map, use:
- 5V Pin 2 or Pin 4 for Power
- GND Pin 6 for Ground
- Pin 33 for PWM
- Pin 35 for Tach.
On the 40-pin header, there are 7 hardware PWM pins 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 or a case directly with a PWM fan.
To test with PWM C on pin 33:
# we cannot enable like we do on Le Potato because pwm-d is already initialized
sudo ldto merge pwm-c-x5
sudo ldto merge pwm-c-x5-fan
sudo reboot
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-c-x5
sudo ldto merge pwm-c-x5-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-c-x5-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.