For this part of the tutorial, you'll need a micro-SD card that's been set up with the
Raspbian operating system, and to be connected to Wi-Fi. It's also really handy to have
a display, keyboard, and mouse connected to your Pi for these next bits.
Open a terminal (press control-alt-t or find it in the Raspberry Pi menu) and then
type the following to install the Fan SHIM Python library:
git clone https://github.com/pimoroni/fanshim-python
cd fanshim-python
sudo ./install.sh
That installs the Python library itself, but we've put together a nice Python script that
sets temperature thresholds (along with a couple of other options) and then turns the
fan on automatically when it reaches a threshold and back off when it drops back below
a second threshold.
The installer accepts three values, the first for the on threshold temperature at which the
fan kicks in, the second for the off threshold temperature at which the fan stops again,
and the third for the delay between each temperature reading.
In our testing, an on threshold of 65°C, an off threshold of 55°C, and a delay of 2 work
pretty well. Type the following in the terminal to run the installer for the automatic script:
cd examples
sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2
This installer will run the automatic script in the background, and it should even start
running again if you shutdown and boot up again, or reboot.
The LED indicates the CPU temperature, with green being cooler and red being hotter.
A long press on the button put the fan into manual mode and then a short press will stop
or start the fan. Long pressing again will re-enable automatic mode.
If you ever need to stop the script running in the background, you can type in the
terminal:
sudo systemctl stop pimoroni-fanshim.service
If you want to change the thresholds, e.g to change the on temperature to 75, the off
temperature to 60, and the delay to 5 seconds, then you can type the following in the
terminal: