Introduction
This post describes how to enable automatic proportional fan speed control that auto-runs when the RaspBMC media centre OS is launched on your Pi.
Although the Pi doesn't get particularly hot when running RaspBMC, this might still be a useful feature to have if your Pi is running in a hot environment, or inside a media centre case with other hardware that generates heat, ie, a mechanical hard drive. The script is written to give temperature vs speed trip-points of 50, 60, 70, 80°C for 25, 50, 75, 100% fan speeds respectively, but details are given at the end of this post to modify this relationship if you so choose.
The easiest way to access your Pi whilst running RaspBMC is via a remote PC using PuTTY for which you will need to know your Pi's IP address. Other methods are available, but this guide assumes that you will be taking this route.
Procedure
Launch PuTTY and log in to your Pi. The standard login and password will be "pi" and "raspberry" unless you've changed them.
1/ Type...
Code: Select all
sudo nano /etc/modules
Code: Select all
i2c-bcm2708
i2c-dev
3/ Add i2c modules to the kernel then reboot your Pi by typing the following three lines at the prompt...
Code: Select all
sudo modprobe i2c-bcm2708
sudo modprobe i2c-dev
sudo reboot
Code: Select all
sudo apt-get install i2c-tools
Code: Select all
sudo nano PCF_fan_control
Code: Select all
#!/bin/bash
#PiCoolFan 5-Speed Fan Controller Using Pi's Own Temp Sensor
#Force disable of plug-and-play fan mode
sudo i2cset -y 1 0x6C 0 1
#Pi sensor temperature measurement and dynamic fan speed update loop
while true
do
speed=$(($(cat /sys/class/thermal/thermal_zone0/temp)/10000-3))
if [ "$speed" -lt 2 ]; then speed=0 ; fi
if [ "$speed" -gt 4 ]; then speed=1 ; fi
sudo i2cset -y 1 0x6C 1 "$speed"
#Set polling interval in seconds
sleep 5
done
7/ Now at the prompt, type...
Code: Select all
sudo chmod +x PCF_fan_control
8/ To auto-run the bash script on boot-up, edit 'rc.local'...
Code: Select all
sudo nano /etc/rc.local
Code: Select all
#Auto-Run PiCoolFan Proportional Control Script
sudo /home/pi/PCF_fan_control &
9/ Finally, reboot your Pi with...
Code: Select all
sudo reboot
Customising Temperature vs Speed Scaling
The 'speed=" line of the bash script determines the relationship between temperature and fan speed. Modifying the "/10000-3))" part of this line is all that's required. A few examples of alternative temperature vs speed relationships are shown in the table below.
Code: Select all
Fan Speed 25% 50% 75% 100%
/10000-3)) 50 60 70 80°C
/9000-4)) 54 63 72 81°C
/7500-6)) 60 67.5 75 82.5°C
/5000-11)) 65 70 75 80°C

Kind regards, GTR2Fan.