How to wire and set PWM fan to GPIO pins and how to control it

Hi, See the attached images.

I want to use the PWM fan in the picture. For this project, I won’t use the Khadas heatsink & fan.

  1. Did I connect the fan to the right pins? If not what pins should be used instead?

  2. http://share.opsy.st/62914ae851123-05_27_2022+Cook+IMAGE+3.png
    The picture in the above link is an example of how I set the temperature when the fan should start and stop when using raspberry pi. Can you give an easy example of how to handle this with khadas?

Thank you!

please check dts
need enable pwm before use it

Thank you. Do you think you can explain more in detail?

Please check the PWM usage documentation.

If I understand correctly the guide is about how to enable and disable the PWM function so first, we should enable it according to your guide. After enabling and going back to my original questions:

. “Did I connect the fan to the right pins? If not what pins should be used instead?”
Yes, PIN: PWM_F

. "http://share.opsy.st/62914ae851123-05_27_2022+Cook+IMAGE+3.png
The picture in the above link is an example of how I set the temperature when the fan should start and stop when using raspberry pi. Can you give an easy example of how to handle this with khadas?"

Can you help further on question 2. about how to set the temperature for the start and stop of the fan?

Thanks

No, PIN35 is PWM PIN, but you connect to PIN39.

Ok, will use pin 35. Was checking on the wrong board gpio map first.

Can you help further on question 2. about how to set the temperature for the start and stop of the fan?

You can create a systemd service and bash script so that it will begin at start up

Script can Read system temprature periodically from /sys/class/thermal/thermal_zone0/temp (milli celcius) after a decision tree filtering appropriate temprature range, set the pwm accordingly

Should be a simple system :slightly_smiling_face:

@numbqq can you check if latest image is able to do pwm without issue ? I keep getting I/O errors and no read write access (instructions followed from the khadas docs)

Hello @Electr1

There are some typos in current documentation, can you check the instructions below?

$ echo 1 | sudo tee  /sys/class/pwm/pwmchip4/export
$ echo 1000000 | sudo tee  /sys/class/pwm/pwmchip4/pwm1/period
$ echo 500000 | sudo tee  /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable

Disable PWM:

$ echo 0 | sudo tee  /sys/class/pwm/pwmchip4/pwm1/enable

yes it works now, thank you! :smile: