FAN
This section introduces how to use the FAN interface function on the Raspberry Pi, laying the foundation for subsequent project development.
tip
- The fan interface is set to automatic temperature control by default and will adjust its speed automatically based on the core temperature. If you need to set the speed manually, it is recommended to switch back to automatic temperature control mode when manual control is no longer needed.
- Please connect the fan before powering on, otherwise the relevant control commands will be ineffective.
FAN Key Notes
- The FAN device on the Raspberry Pi defaults to
/sys/devices/platform/cooling_fan/hwmon/hwmon/pwm1(The fan device is only recognized if connected before powering on)
Manual Speed Control
Note:
The fan interface is set to automatic temperature control by default and adjusts its speed based on the core temperature. Setting the speed manually will disable the automatic temperature control function. It is recommended to switch back to automatic mode when manual control is not required.
- Refer to the relevant notes: FAN Key Notes
- Check if the fan device exists (the device exists if the command outputs a listing)
ls /sys/devices/platform/cooling_fan/hwmon/hwmon0 - Switch to manual control (automatic temperature control is default)
echo 1 | sudo tee /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1_enable
# sudo echo 1 > /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1_enable - Set fan speed to 100% (255: fan speed value, range 0~255)
echo 255 | sudo tee /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1
# sudo echo 255 > /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1 - Set fan speed to 50% (255: fan speed value, range 0~255)
echo 128 | sudo tee /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1
# sudo echo 128 > /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1 - Set fan speed to 0% (255: fan speed value, range 0~255)
echo 0 | sudo tee /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1
# sudo echo 0 > /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1
View Current Speed
- Refer to the relevant notes: FAN Key Notes
- Check if the fan device exists (the device exists if the command outputs a listing)
ls /sys/devices/platform/cooling_fan/hwmon/hwmon0 - Print the current fan speed
cat /sys/devices/platform/cooling_fan/hwmon/hwmon0/fan1_input
Restore Automatic Temperature Control
- Refer to the relevant notes: FAN Key Notes
- Check if the fan device exists (the device exists if the command outputs a listing)
ls /sys/devices/platform/cooling_fan/hwmon/hwmon0 - Switch to automatic temperature control
echo 2 | sudo tee /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1_enable
# sudo echo 2 > /sys/devices/platform/cooling_fan/hwmon/hwmon0/pwm1_enable