Using PiCoolFan with RaspBMC

Advanced Pi Cooling Fan System with Real Time Clock

Using PiCoolFan with RaspBMC

Postby GTR2Fan » Mon Jun 02, 2014 2:35 pm

Using PiCoolFan with RaspBMC



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


2/ Add i2c to modules by adding the following two lines...
Code: Select all
i2c-bcm2708
i2c-dev

...then exit nano with Ctrl-X, Y, Enter.


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


4/ Install i2c tools by typing...
Code: Select all
sudo apt-get install i2c-tools


5/ Launch nano by typing...
Code: Select all
sudo nano PCF_fan_control


6/ Copy and paste the following into nano...
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

...then exit nano with Ctrl-X, Y, Enter.


7/ Now at the prompt, type...
Code: Select all
sudo chmod +x PCF_fan_control

...to make the bash script executable.


8/ To auto-run the bash script on boot-up, edit 'rc.local'...
Code: Select all
sudo nano /etc/rc.local

...and add a call to the script immediately before the 'exit 0' line thus...
Code: Select all
#Auto-Run PiCoolFan Proportional Control Script
sudo /home/pi/PCF_fan_control &

...then exit nano with Ctrl-X, Y, Enter.


9/ Finally, reboot your Pi with...
Code: Select all
sudo reboot


Job done!



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


Enjoy! :)

Kind regards, GTR2Fan.
User avatar
GTR2Fan
 
Posts: 3
Joined: Wed May 14, 2014 5:15 pm

Return to PiCoolFan

Who is online

Users browsing this forum: No registered users and 1 guest