PINE64

Full Version: Fan speed controlled by CPU temp script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I wrote a script to control my fan.
The fan speed is controlled by the temp of the CPU.
I'm pretty new to bash so I'm hoping for some feedback and off course is everybody free to use the script how they like. Big Grin

Code:
#!/bin/bash
#MikeD
#Automatic fan on cpu temp

CHECK_TIME=10 #IN SEC

function pwm(){
LOOP=0
while [ $LOOP -lt $(($CHECK_TIME*75)) ]; do
       echo 1 > /sys/class/gpio/gpio82/value
       sleep $1
       echo 0 > /sys/class/gpio/gpio82/value
       sleep $2
       LOOP=$(($LOOP+1))
done
}

function fanOff()
{
echo 0 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}

function fanTweFiv()
{
pwm .0025 .0075
}

function fanFifty()
{
pwm .0050 .0050
}

function fanSevFiv()
{
pwm .0075 .0025
}

function fanFull()
{
echo 1 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}

while [ 1 ]; do
       TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)

       if [ $TEMP -le 20000 ]
       then
               fanOff
       fi
       if [ $TEMP -gt 20000  -a  $TEMP -le 35000 ]
       then
               fanTweFiv
       fi

       if [ $TEMP -gt 35000 -a $TEMP -le 50000 ]
       then
               fanFifty
       fi

       if [ $TEMP -gt 50000 -a $TEMP -le 65000 ]
       then
               fanSevFiv
       fi

       if [ $TEMP -gt 65000 ]
       then
               fanFull
       fi

done

Thx in advance Smile
Hey there, how is this script holding up today? Has anyone been using it?
Can't get it to work:

./fantemp.sh: line 10: /sys/class/gpio/gpio82/value: No such file or directory
./fantemp.sh: line 12: /sys/class/gpio/gpio82/value: No such file or directory

I have these gpio's:

[email protected]:/sys/class/gpio$ ls
export gpiochip0 gpiochip32 gpiochip510 gpiochip64 gpiochip96 unexport