Skip to main content

Fan Shim for Raspberry Pi

Build Status Coverage Status PyPi Package Python Versions

Installing

Stable library from PyPi:

  • Just run sudo pip install fanshim

Latest/development library from GitHub:

  • apt install git python3-pip
  • git clone https://github.com/pimoroni/fanshim-python
  • cd fanshim-python
  • sudo ./install.sh

Reference

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

from fanshim import FanShim
fanshim = FanShim()

Fan

Turn the fan on with:

fanshim.set_fan(True)

Turn it off with:

fanshim.set_fan(False)

You can also toggle the fan with:

fanshim.toggle_fan()

You can check the status of the fan with:

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

LED

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)

Button

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

Do something when the button is pressed:

@fanshim.on_press()
def button_pressed():
    print("The button has been pressed!")

Or when it has been released:

@fanshim.on_release()
def button_released(was_held):
    print("The button has been pressed!")

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

fanshim.set_hold_time(2.0)

@fanshim.on_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:

@fanshim.on_release()
def button_released(was_held):
    if was_held:
        print("Long press!")
    else:
        print("Short press!")

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

fanshim.set_hold_time(number_of_seconds)

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

fanshim.stop_polling()

You can start it again with:

fanshim.start_polling()

Alternate Software

0.0.5

  • Replace Plasma API with APA102 library
  • Add support for setting LED global brightness
  • Add support for disabling button and/or LED
  • Move packages/requires to setup.config, minimum version now Python 2.7

0.0.4

  • Prepare Fan SHIM to use legacy Plasma API

0.0.3

  • Fix: lower polling frequency and make customisable, for PR #6

0.0.2

  • Fix: Fix error on exit

0.0.1

  • Initial Release

Release files for fanshim 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fanshim 0.0.5
File Size Uploaded
fanshim-0.0.5.tar.gz 5.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fanshim 0.0.5
File Interpreter ABI Platform
fanshim-0.0.5-py3-none-any.whl Python 3 none any Details
fanshim-0.0.5-py2-none-any.whl Python 2 none any Details

Total release size: 14.8 kB

Release files / fanshim-0.0.5.tar.gz

Download URL fanshim-0.0.5.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
65a1b8004608a76f4baffa1c50a4305a4a1b412e5f9d47398286b2657af084da
BLAKE2b-256 checksum
How to use checksums
5d252ef5204c16a1448236e7e243c4310313a6eb176177447015e189225d648d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release files / fanshim-0.0.5-py3-none-any.whl

Download URL fanshim-0.0.5-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebca51219a020f23f327ef3a88b13fe3501f3e6f84533500ed4be778c4522985
BLAKE2b-256 checksum
How to use checksums
873a21742a58ef7bd1b5ada4031d40c67cb94c3a3630541749111337cb35d7b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release files / fanshim-0.0.5-py2-none-any.whl

Download URL fanshim-0.0.5-py2-none-any.whl
Size 4.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
c293251604a52436bd211956610100dbfd3d508d7b2f8b1defe50f17ffa6b7c5
BLAKE2b-256 checksum
How to use checksums
73a5ac458ddc4adda6ae46745659544ec7edf2f3fa244823fd52226472cfff38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.5 This release

3 release files

0.0.4

3 release files

0.0.3

3 release files

0.0.2

3 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page