Giter Club home page Giter Club logo

fanctl's Introduction

fanctl

A simple thermal fan controller for Raspbian.

中文文档

Hardware

Required parts

  • 5V DC fan x1, 3mm / 4mm or any other size suitable for your Raspberry Pi.
  • 2N2222 NPN transistor x1.
  • 680ohm resistor x1.
  • (Optional) small piece of PCB. If you don't have one, it is also possible to solder all parts directly to the fan wires..

The circuit

the circuit

Or you could reference to this post for connecting your parts together.

Choose any GND / VCC (5V) pin to supply power. For the controller pin, use GPIO 8 (AKA BCM 14).

Software

Install dependencies

  • First of all update apt cache: sudo apt update.
  • Install cmake, gcc and git, as you would do for all other C projects: sudo apt install cmake build-essential gcc git.
  • Install the MRAA lilbrary for accessing GPIO:
    • Clone MRAA project: git clone https://github.com/eclipse/mraa.git
    • Enter the cloned repository: cd mraa
    • Prepare to build: mkdir build && cd build
    • Generate makefiles: cmake ..
    • Build: make
    • Install the built tools: sudo make install
    • Refresh linker related stuff so MRAA library can be located by gcc: sudo ldconfig -v
    • To verify you have correctly installed the MRAA library, run mraa-gpio version, it should print the model of your Raspberry Pi

Build this project

  • Clone this project: git clone https://github.com/JokerQyou/fanctl.git
  • Enter the cloned repository: cd fanctl
  • Prepare to build: mkdir build && cd build
  • Generate makefiles: cmake ..
  • Build: make
  • Install: sudo make install

Start service

  • Reload systemd units: sudo systemctl daemon-reload
  • To verify you have correctly installed the service, run sudo systemctl status fanctl, it should print some information about this tool
  • To start the service: sudo systemctl start fanctl

When the chip temperature reaches 60°C, the fan will be started by pulling FAN_VCC_PIN to high (causing the transistor to close). When the chip temperature drops to 45°C or below, the fan will be stopped by pulling FAN_VCC_PIN to low. When the fan is started or stopped, the corresponding temperature value will be written to journald logs, to follow the log: sudo journalctl -u fanctl -f.

Configure

Edit the installed service file (in /etc/systemd/system), use THRESHOLD_ON and THRESHOLD_OFF to set temperature limits. ON is the upper limit, fan starts when chip temperature reaches above it; OFF is the lower limit, fan stops when chip temperature drops below it.

[Service]
# ...
Environment=THRESHOLD_ON=50
Environment=THRESHOLD_OFF=30

You'll need to reload the daemon before restarting the service:

sudo systemctl daemon-reload
sudo systemctl restart fanctl

To use a different pin for controlling the fan, modify FAN_VCC_PIN (Notice: MRAA library uses the physical pin number). Then rebuild and reinstall again. Service will need to be restarted.

Why C

Well, I've actually written a Python script and installed that as a service, it kept working for almost 6 months. But I don't think such a simple job is worth using 15MB of memory. The memory footprint dropped under 400KB after transforming to C.

fanctl's People

Contributors

jokerqyou avatar

Stargazers

 avatar

Watchers

 avatar  avatar

fanctl's Issues

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.