Rock 4 SE setup Ubuntu automatic fan control PWM

Hello!
Can someone guide me on how to set up a PWM fan? I am able to control it manually with changing the values for period:

echo 0 > /sys/class/pwm/pwmchip0/export
sleep 0.2
echo 40000 > /sys/class/pwm/pwmchip0/pwm0/period
sleep 0.2
echo 10000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
sleep 0.2
echo normal >  /sys/class/pwm/pwmchip0/pwm0/polarity
sleep 0.2
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable

But how can I set up different values for different temperatures automatic on boot?

Thank you in advance!

create a bash script or Python script. various options available to load on boot. e.g. using rc.local or similar.

tutorials can be found online for guidance. e.g. https://www.baeldung.com/linux/run-script-on-startup

Could you enlighten me, how you got the fan working via the command line in first place?
I am still trying and it does not move. This is what I did:

  • I have ubuntu server installed with kernel 4.4.194-11-rk3399-rockchip-g1bb08d49cc40
  • set intfc:pwm0 to on in /boot/hw_intfc.conf
  • connected the fan to pins 9 (gnd) and 11 (pwm0)
  • fired the commands you used
    Nothing happens.

I appreciate any pointers that get me and my fan moving again