Giter VIP home page Giter VIP logo

fanshim-python-pwm's Introduction

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 https://github.com/pimoroni/fanshim-python
All the changes made are in "fanshim/library/fanshim/__init__.py". I have added some tmux files to enable running /examples/automatic.py automatically at start up.

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

See the "Volumio Branch" for a version adapted for running on Volumio ( https://volumio.org/ ) [https://github.com/grayerbeard/fanshim-python-pwm/tree/volumio]

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 https://github.com/grayerbeard/fanshim-python-pwm.git /home/pi/fanshim
  • at the /home/pi/fanshim directory enter "sudo ./install.sh"
  • go to "/home/pi/fanshim/example" and test by entering
  • "python3 automatic.py --on-threshold 46 --off-threshold 44 --delay 6 --brightness 2 –verbose”
  • fan should run as Pi warms up, stop running by typing "ctrl c"
  • install tmux if not installed already using "sudo apt install tmux"
  • test the tmux file by entering "./tmux_start.sh" 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/tmux_start.sh &" 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". (Also edit the directories in tmux_start.sh to replace "pi" with "volumio" and change the directory used when you edid rc.local to suite the location of the code.)

On some syatms the ./tmux_stress.sh 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 ./install.sh)

  • 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/__init__.py 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

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

fanshim-python-pwm's People

Contributors

gadgetoid avatar grayerbeard avatar dt-was-an-et avatar jcoetzee avatar magnu5 avatar burtyb avatar ednl avatar haggistech avatar sandyjmacdonald avatar seanhandley avatar jesterret avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.