Fan Speed Script

Moderators: mdrjr, odroid

Fan Speed Script

Unread postby xana » Wed Aug 27, 2014 8:24 pm

Hello everyone,

I didn't find a good script for my needs for speed controling the fan of my odroid. So I wrote my own.

Between 40-50°C the fan will be at low speed, otherwise will be auto controlled. Delay is 10 seconds.
This script give another curve than which is possible with just the auto mode.

Perhaps it's usefull for somebody else ;)

PS: I'm still improving it, so it may change :)

Code: Select all
#!/bin/bash

last=0
var=100000
#set auto start_temp to 50
echo 50 > /sys/devices/platform/odroidu2-fan/start_temp



while true; do
sleep 10
var=$(< /sys/devices/virtual/thermal/thermal_zone0/temp)
echo $var

echo $last

if [ $var -lt 50000 ] && [ $var -gt 40000 ];then

if [ $last -eq 1 ] || ( [ $last -eq 2 ] && [ $var -le 42000 ] );then
continue
fi

last=1
echo manual > /sys/devices/platform/odroidu2-fan/fan_mode

echo 100 > /sys/devices/platform/odroidu2-fan/pwm_duty
sleep 1
echo 34 > /sys/devices/platform/odroidu2-fan/pwm_duty


echo "low speed"
else

if [ $last -eq 2 ];then
continue
fi


last=2
echo auto > /sys/devices/platform/odroidu2-fan/fan_mode
echo "auto"

fi

done
xana
 
Posts: 2
Joined: Wed Aug 27, 2014 8:09 pm
languages_spoken: english, german
ODROIDs: U3+

Re: Fan Speed Script

Unread postby rockchip » Mon Sep 08, 2014 9:53 pm

As I understand you needed the script to initiate cooling earlier - starting from 40C, with pwm_duty re-iterating the speeds of 100 and 34 , until it reaches 50C from where it goes on in the usual "auto" mode. It looks like you had to write that algorithm that because of an increased CPU load your device has to tackle, not bad.

In case if your fan/u3 had some problem that was the reason for writing the script, it seems some U3's fan problems (like squeaking sounds and whistling) are fixed by the latest kernel update managed via odroid-utility. Not sure if the U3+ handles fans any differently, though.
rockchip
 
Posts: 51
Joined: Fri Jul 25, 2014 1:45 am
languages_spoken: english
ODROIDs: Odroid U3 Linux Transcend 8GB

Re: Fan Speed Script

Unread postby xana » Tue Sep 09, 2014 4:15 am

Thanks for the information. My fan seems to work without problems.
I just don't want that the fan goes on because of some short CPU spikes. But when there is low CPU usage the heat sink gets hotter over 30-60 seconds in ther case the fan isn't working. This script ensures that the fan goes on until the temperature is low enough.

PS: I improved the script a lot, perhaps someone wants to have a look at it, my next step is something like turbo boost known from Intel. When the CPU is cool enough i want to clock the CPU to 2.0GHz and down to 1.2Ghz if the CPU is too hot. When there is only one process eating 100 percent then the CPU will overclock, when there are more processes with much load, the CPU will go down to 1.2GHz each. This will ensure that the fan doesn't have to go higher than a defined speed.

Current script, yet without "turbo boost".
Code: Select all
#!/bin/bash

#displa  cursor again at EXIT
unhide_cursor() {
    printf '\e[?25h'
    clear
}
trap unhide_cursor EXIT


last=0
last_temp=0
var=100000
#set auto start_temp to 50
echo 55 > /sys/devices/platform/odroidu2-fan/start_temp
mean=80000

#hide cursor
printf '\e[?25l'
clear

while true; do

#move cursor to top
printf '\033[;H'
sleep 1
last_temp=$var
var=$(< /sys/devices/virtual/thermal/thermal_zone0/temp)
current_speed=$(< /sys/devices/platform/odroidu2-fan/pwm_duty)
echo $var

#echo "$var,${current_speed:22:3}" >> history

echo $last

mean=$(echo "$mean/10*9+$var/10" |bc -l)


echo $mean
echo ${mean%.*}

var=${mean%.*}

if [ $var -lt 60000 ] && [ $var -gt 50000 ];then

if [ $last -eq 1 ] || ( [ $last -eq 2 ] && [ $var -le 54000 ] );then
continue
fi

last=1
echo manual > /sys/devices/platform/odroidu2-fan/fan_mode

echo 100 > /sys/devices/platform/odroidu2-fan/pwm_duty
sleep 1
echo 40 > /sys/devices/platform/odroidu2-fan/pwm_duty


echo "low speed"
else

if [ $last -eq 2 ];then
continue
fi


last=2
echo auto > /sys/devices/platform/odroidu2-fan/fan_mode
echo "auto"

fi

done
xana
 
Posts: 2
Joined: Wed Aug 27, 2014 8:09 pm
languages_spoken: english, german
ODROIDs: U3+


Return to General Chat

Who is online

Users browsing this forum: No registered users and 2 guests