Skip to content
Pimorini Fanshim Code version 0.0.4 (february 2020) modified so fan runs slower and Quieter using PWM.
Python Shell Makefile
Branch: master
Clone or download

What is this

This is a modified version of the code for the Pimorini cooling fan set to run the Fan slower and quieter using Pulse Width Modulation (PWM). This is based on version 0.0.4 cloned on February 25th 2020 from
All the changes made are in "fanshim/library/fanshim/". I have added some tmux files to enable running /examples/ automatically at start up.

There is a txt file showing the changes needed to /etc/rc.local

In a 100% load test for 15 minutes at 80% speed the CPU temperature on my R Pi 4 (not over clocked) settled at 59 degrees C.

Suggested method to install

My preferred way to install this software is to clone it using Git and then run it using tmux as described below.

  • open a terminal
  • make a director using "mkdir fanshim" so that it is "/home/pi/fanshim"
  • clone into that directory using "git clone /home/pi/fanshim
  • at the /home/pi/fanshim directory enter "sudo ./"
  • go to "/home/pi/fanshim/example" and test by entering
  • "python3 --on-threshold 46 --off-threshold 44 --delay 6 --brightness 2 –verbose”
  • fan should run soon as Pi warms up to these fairly low temperature settings, stop running by typing "ctrl c"
  • install tmux if not installed already using "sudo apt install tmux"
  • test the tmux file by entering "./" check its running with "tmux ls" observe with "tmux a -t fanshim"
  • edit "/etc/rc.local" using the command "sudo nano /etc/rc.local" to add "sudo -u pi bash /home/pi/fanshim/ &" before "exit 0" at the end of the file.
  • reboot and code should run automatically. You can check its running by entering "tmux ls" in a terminal.

The original method of install and run as detailed below should also work but I have not tested it as I prefer using tmux as I find it easier if I want to check what is going on or make changes. If on your system you have a different user directory, e.g. on volumio you would have "volumio" instead of "pi" then in every case above replace "pi" with "volumio". (Als edit the directoris in tmux) to replace "pi" with "volumio")

On some syatms the ./ command will not work due to lack of working vcgencmd and stress.

On some other OS like volumio you may also need to do all or some these commands before running the code (after doing sudo ./

  • sudo apt update
  • sudo apt install python3
  • sudo apt install python3-pip
  • sudo pip3 install RPi.GPIO
  • sudo pip3 install psutil --upgrade

PWM Parameters

These are set within /fanshim/library/fanshim/ in this snipit of code (frequency 4 Hz, PWM % 80)

    self.pwm_freq = 4
    self.pwm_speed = 80

These can be adjusted as required but only a limited range of values work.

Original Pimorini Readme file...........

Fan Shim for Raspberry Pi

Build Status Coverage Status PyPi Package Python Versions


Stable library from PyPi:

  • Just run sudo pip install fanshim

Latest/development library from GitHub:

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


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:


Alternate Software

You can’t perform that action at this time.