PINE64
Fan speed controlled by CPU temp script - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: ROCK64 (https://forum.pine64.org/forumdisplay.php?fid=85)
+--- Forum: Rock64 Hardware and Accessories (https://forum.pine64.org/forumdisplay.php?fid=89)
+--- Thread: Fan speed controlled by CPU temp script (/showthread.php?tid=5374)



Fan speed controlled by CPU temp script - mikedhoore - 11-18-2017

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


RE: Fan speed controlled by CPU temp script - va88 - 12-22-2018

Hey there, how is this script holding up today? Has anyone been using it?


RE: Fan speed controlled by CPU temp script - va88 - 01-14-2019

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:

rock64@rock64:/sys/class/gpio$ ls
export gpiochip0 gpiochip32 gpiochip510 gpiochip64 gpiochip96 unexport