Is there a way to run some kind of PWM for fan speed control inside bash script?
Here is my current script
#!/bin/bash
### BEGIN INIT INFO
# Provides: rpipwm
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: rpipwm
### END INIT INFO
a="echo 20 > /sys/class/gpio/unexport;"
a=$a"echo 20 > /sys/class/gpio/export;"
a=$a"echo out > /sys/class/gpio/gpio20/direction"
eval $a
#start loop script
while true;
do
#Read temp
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
temp=$cpuTemp1
a=""
#If temperature is equal or lower than 39, the fan will stop spinning
if [[ $(bc <<< "$temp <= 39") == 1 ]] ;
then
a=$a"echo 0 > /sys/class/gpio/gpio20/value"
fi
#If temperature is between 40 and 42.99, the fan will start with 2 second burst and 1 second sleep
if [[ $(bc <<< "$temp >= 40 && $temp <= 43") == 1 ]] ;
then
a=$a"echo 1 > /sys/class/gpio/gpio20/value; sleep 2; echo 0 > /sys/class/gpio/gpio20/value; sleep 1 "
fi
#If temperature is between 44 and 48.99, the fan will start with 5 second burst and 1 second sleep
if [[ $(bc <<< "$temp > 44 && $temp <= 49") == 1 ]] ;
then
a=$a"echo 1 > /sys/class/gpio/gpio20/value; sleep 5; echo 0 > /sys/class/gpio/gpio20/value; sleep 1"
fi
#If temperature is equal or higher than 50, the fan will start spinning constantly
if [[ $(bc <<< "$temp >= 50") == 1 ]] ;
then
a=$a"echo 1 > /sys/class/gpio/gpio20/value"
fi
eval $a
sleep 0.1
done
I want to avoid sleep or somehow simulate PWM to my fan have real speed control instand of ON/OFF in defined intervals.
Can someone help me?
Thanks!