Skip to main content

Python library for the Pimoroni Fan Shim for Raspberry Pi

Project description

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:

  • 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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fanshim-0.0.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distributions

fanshim-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

fanshim-0.0.4-py2-none-any.whl (4.6 kB view details)

Uploaded Python 2

File details

Details for the file fanshim-0.0.4.tar.gz.

File metadata

  • Download URL: fanshim-0.0.4.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for fanshim-0.0.4.tar.gz
Algorithm Hash digest
SHA256 449a37fbfdba064b0f93d37846f66e4f76c40060bc07501be1ee6b5dd8133fd3
MD5 2f893d4c6f330fef42f0391f03b97614
BLAKE2b-256 80e6021c9a08ced01861e7afec8884c5623882631037c9debb498822fac62ccf

See more details on using hashes here.

File details

Details for the file fanshim-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: fanshim-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for fanshim-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0e28a0cb5358bfc79954da45459b77de759d0dbf419edccf46729a9c811bdcd2
MD5 5b42f1dd42fba58b9ecd7df1b67c4820
BLAKE2b-256 b517d17fba80d3b5c31991b0020000b4739c959b85ddadd66160c2ae62d03146

See more details on using hashes here.

File details

Details for the file fanshim-0.0.4-py2-none-any.whl.

File metadata

  • Download URL: fanshim-0.0.4-py2-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for fanshim-0.0.4-py2-none-any.whl
Algorithm Hash digest
SHA256 2f813ddcd7f16aff884c0356ef2d7411b167498d853e126c5ba4e2eee1ca4d18
MD5 9cbfa21c80ccc70985957a6cd8ba719d
BLAKE2b-256 e71444f8f5640a3a53e79ab6fc7c69af95f44f138bd5773939c7a343bb3549ee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page