https://github.com/snapstromegon/fan_control
SysFS fan control written in Rust, primarily for Raspberry Pis.
https://github.com/snapstromegon/fan_control
fan-control raspberry-pi raspberry-pi-4 rust rust-lang sysfs sysfs-gpio
Last synced: about 1 month ago
JSON representation
SysFS fan control written in Rust, primarily for Raspberry Pis.
- Host: GitHub
- URL: https://github.com/snapstromegon/fan_control
- Owner: Snapstromegon
- License: isc
- Created: 2021-10-19T18:52:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-01T15:56:19.000Z (over 4 years ago)
- Last Synced: 2025-04-03T14:26:36.567Z (about 1 year ago)
- Topics: fan-control, raspberry-pi, raspberry-pi-4, rust, rust-lang, sysfs, sysfs-gpio
- Language: Rust
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# Fan Control
This is a fan control for a Raspberry PI based on the SYSFS interface.
It should be compatible with any SYSFS compatible system which exposes the GPIO pins and thermal zones.
## Hardware Setup


I'm using these fan heatsinks for my Pis: [Amazon](https://www.amazon.de/dp/B07VD6NC8P/ref=cm_sw_em_r_mt_dp_THBAEA29Y04XN7V86SXB) / [Reichelt](https://www.reichelt.de/gehaeuse-fuer-raspberry-pi-4-alu-luefter-schwarz-rpi-case-alu07f-p261678.html?)
You connect the red wires from the fans to one of the two red pins from the Pi.
The black wire from the fan gets cut in the middle and the part connected to the fan gets soldered to the _emitter_ pin of a transistor and the part leading to the Pi to the _collector_ pin of the transistor.
Finally connect the _base_ pin of the transistor to any GPIO pin (I used 23 and grabbed ground from the one next to it) with a resistor in between (I used a 1k Ohm one).
## Software Setup
### Get Binary
#### Download Release for your system
I currently publish 64 Bit Arm binarys, since I'm developing this for my Pi 4s.
| System | Release Binary |
| :------------------ | :------------------------------------------------------------------------------------------------------- |
| Raspberry Pi 64 Bit | [fan_control](https://github.com/Snapstromegon/fan_control/releases/latest/download/fan_control) |
#### Self Compile
##### Install Rust (with rustup)
```sh
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
##### Download or clone Sourcecode
Download the source from either the release, or the master of this repo.
```sh
$ git clone git@github.com:Snapstromegon/fan_control.git
$ cd fan_control
```
##### Compile
Inside of the project folder run:
```sh
$ cargo build --release
```
(Resulting binary will be $pwd/target/aarch64-unknown-linux-gnu/release/fan_control)
### Copy Binary and Systemd service
Copy the fan*control bin to */opt/fan*control* and the _fan_control.service_ (example in this repo) to _/etc/systemd/system/fan_control.service_.
### Configure
You can either configure the program via anfironment variables or command line arguments (for both, check `fan_control --help`).
You can configure:
- **GPIO Pin:** The pin which is used to turn the fan on/off
- **Thermometer Path:** SysFS path of the thermometer (should result in °C\*1000 - so 40000 = 40°C)
- **Fan On Temperature:** When should the fan kick in
- **Fan Off Temperature:** When should the fan turn off again
- **Log Level:** Use the _RUST_LOG_ environment variable to change the log level. The default is "info".
### Enable Systemd service
```sh
$ systemctl enable --now fan_control
```