Skip to content
Pimorini Software modified so Fan runs slower using PWM tested OK December 6th to 14th 2019.
Python Shell Makefile
Branch: master
Clone or download
Pull request Compare This branch is 24 commits ahead, 12 commits behind pimoroni:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
log dec 7th 1.csv

Pimorini Python modified successfully to run Fan only as fast as needed using a fixed PWM speed

Note 14 12 2019

  • Have used this on my R Pi 4 over a week now and works fine in either verbode mode or not in Verbose mode.

Notes 07 12 2019:

  • I ran into a problem related to the push button that kept turning off the auto mode, maybe because this code is not based on the latest pimorini version. I think this may be 0.0.2 based and they are up to 0.0.3. However the actual control of the fan is working fine I just had to remark out some code related to the push button. I have no plans, at the moment, to investigate as this version is fine for my purposes.
  • I have added logging to a csv file when in verbose mode and a tmux start file for starting not in verbose mode.
  • I have fine tuned the parameters used in the tmux commands with respect to temperatures, reprate etc.

It does not make much difference how fast the fan is running as long as its putting enough colder air by the cpu it gets cooled about the same. (tests done using the algoritmm in the pwm_fanshim branch of my RPi4_Python_FanshimPWM_Temperature_Control_with_logging repository. 70 to 75% speed is well fast enough and is much quieter.

Although the cooling effect is arount 30 to 40% less its actually enough to cool the CPU when running a 100% load stress test down to around 62 C.

December 6th 1200hrs

  • (1) Modified so that when command given to run fan it should run at 70% speed instead of 100%. Extensive test have shown that the cooling effect is very similar at a slower speed and yet the fan is much quieter. Then added a command that can be usd to run in a tmux session.
  • (2) Installed and tests completed December 6th 1420hrs. Ran 100% stress test and cooling OK with fan running at 70% speed instead of 100%. Temperatures used; On at 65 off at 60. Will later install logging to check long term behaviour.

Fan Shim for Raspberry Pi

Build Status Coverage Status PyPi Package Python Versions


Stable Pimorini version library from PyPi:

  • Just run sudo pip install fanshim

Latest/development library from THE PIMORINI GitHub:

  • git clone
  • cd fanshim-python
  • sudo ./

My "Slower Speed Development" library from HERE using PWM to run fan slower:

Install and run in a tmux session using my version of

  • cd /home/pi
  • git clone
  • cd /home/pi/fanshim-python
  • sudo ./
  • ./


  • If not installed install tmux with sudo apt-get install tmux
  • To start automatically put this into rc.local using sudo nano /etc/rc.local : sudo -u pi bash /home/pi/fanshim-python/ &
  • To change parameters used edit
  • To check if tmux session running OK use tmux ls
  • To observe program output use tmux a -t fanshim_pwm
  • To leave tmux seession use ctrl-b d

Reference by Pimorini for using the original Pimorini code commands in your own Python Program

You should first set up an instance of the FANShim class, eg:

from fanshim import FanShim
fanshim = FanShim()


Turn the fan on with:


Turn it off with:


You can also toggle the fan with:


You can check the status of the fan with:

fanshim.get_fan() # returns 1 for 'on', 0 for 'off'


Fan Shim includes one RGB APA-102 LED.

Set it to any colour with:

fanshim.set_light(r, g, b)

Arguments r, g and b should be numbers between 0 and 255 that describe the colour you want.

For example, full red:

fanshim.set_light(255, 0, 0)


Fan Shim includes a button, you can bind actions to press, release and hold events.

Do something when the button is pressed:

def button_pressed():
    print("The button has been pressed!")

Or when it has been released:

def button_released(was_held):
    print("The button has been pressed!")

Or when it's been pressed long enough to trigger a hold:


def button_held():
    print("The button was held for 2 seconds")

The function you bind to on_release() is passed a was_held parameter, this lets you know if the button was held down for longer than the configured hold time. If you want to bind an action to "press" and another to "hold" you should check this flag and perform your action in the on_release() handler:

def button_released(was_held):
    if was_held:
        print("Long press!")
        print("Short press!")

To configure the amount of time the button should be held (in seconds), use:


If you need to stop Fan Shim from polling the button, use:


You can start it again with:

You can’t perform that action at this time.