This is a small script I wrote to control basic non-PWM fans using cheap TB6612/DRV8833 PWM drivers.
The script has a config.json with several parameters:
-
"cpu_fan"/"hdd_fan"-
"fan_config"Configure the IN1, IN2 and PWM pins according to your wiring. Recommended frequency is 100Hz for most fans. Some fans have really slow startup and do not work well at higher frequencies (1kHz+). -
"fan_curve"Here one may configure the fan curve."low_speed"is the PWM speed when the temperature sensor is greater than or equal to the"low"temperature and less than the"mid"temperature. Any temperature greater than or equal to"high"will set the fan to 100%. Values between"low_speed"and 100% are interpolated.
-
The pigpio module is required. It is recommended to install pigpio on Raspberry Pi OS or Raspbian using the following:
sudo apt-get update
sudo apt-get install pigpio python-pigpio python3-pigpio
After a successful installation, enable the pigpio daemon to run on boot:
sudo systemctl enable pigpiod
This script is designed to run as a background process. Create a bash script consisting of this one line:
nohup python fan_control.py --no-hdd > /dev/null 2>&1 &
and add it to your crontab with @reboot. The script will run in the background without interruption on boot.