Fan Controller

Moderators: mdrjr, odroid

Fan Controller

Unread postby TampaPowers » Mon Apr 16, 2018 11:25 pm

Saw the recent blog post and remembered that I had written a fan control script in bash a while back that would keep the temperature in a more reasonable range and turn the fan on earlier and slower. The script itself can likely be easily adapted to other odroids, but it was specifically designed for my u3+ initially. Nothing fancy, but I suppose in the name of open software I should give some back huh. It probably makes sense to set it up as service on boot as well so you don't have to start it manually like I do. Feel free to use for whatever, might make sense to attach something like it to the wiki page mentioned in that blog post as well.

Code: Select all
#!/bin/bash
# version 0.3.4 2011-06-12 (YYYY-MM-DD)

main() {

  echo "manual" > /sys/devices/platform/odroidu2-fan/fan_mode

  while :
  do
 
    while read line; do
      var="$var $line"
    done < /sys/devices/virtual/thermal/thermal_zone0/temp
 

    fanspeed=`expr $var \\* $var / 18 / 1000`
    fanspeed=`expr $fanspeed / 1000`
 
    temps=`expr $var / 1000`
 
    cd /
    if [ "$temps" \< "30" ] ; then
      fanmode='off'
      echo "0" > /sys/devices/platform/odroidu2-fan/pwm_duty
    elif [ "$temps" \> "30" ] ; then
      fanmode='on'
      echo "$fanspeed" > /sys/devices/platform/odroidu2-fan/pwm_duty
    fi
   
    timestamp=$(date '+%F-%H-%M')
    echo -e "At $timestamp Temp: $temps Fanmode: $fanmode Fanspeed: $fanspeed" >> /var/log/temp_log.txt
   
    var=''
    fanspeed=''
    temps=''
    fanmode='off'
 
    sleep 2
 
  done
 
}

case "$1" in
  *)
  main
  ;;
esac

exit 0
TampaPowers
 
Posts: 13
Joined: Sat May 18, 2013 6:34 am
languages_spoken: english
ODROIDs: X2, U3+

Re: Fan Controller

Unread postby odroid » Tue Apr 17, 2018 9:57 am

Thank you for sharing the script.
I've added this topic to the WiKi page.
https://wiki.odroid.com/odroid-xu4/appl ... p_examples
User avatar
odroid
Site Admin
 
Posts: 28257
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID


Return to Ubuntu

Who is online

Users browsing this forum: No registered users and 2 guests