Scenario: I want to control a PC fan using the Raspberry Pi. The 4-wire-fan (MGT9212UR-W25) has its own power supply (12V) and can be controled via PWM. I would like to control it with a Python script using the RPi.GPIO
module, which unfortunately leads to bad results with a loud creaking noise. The fan's PWM input is connected to the Raspberry Pi on pin 12 (BCM). I would like to set the speed to 20% (for this example).
Good results: GPIO command line utility
gpio -g mode 12 pwm
gpio pwmr 100
gpio -g pwm 12 20
Bad results: RPi.GPIO module using Python 3.5
from RPi import GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
pwm = GPIO.PWM(12, 50)
pwm.start(0)
pwm.ChangeDutyCycle(20)
Question: Both attemps work, but the command line utility always leads to smooth results (pwmr
not required), while the Python script leaves me with a crackling fan (loud). I tried different values for ChangeDutyCycle and ChangeFrequency, so what am I doing wrong? How can the good results (from the command line utility) be produced using RPi.GPIO in Python? Thanks!!