Giter VIP home page Giter VIP logo

opi5-fan-control's Introduction

Orange Pi 5: PWM Fan Control

This script written in C language reads the CPU temperature and adjusts the fan speed based on that information. Before the script can work, wiringOP needs to be downloaded and installed from Git to enable the use of GPIO pins. Additionally, the script needs to be compiled after it's downloaded.

Requirements

Installation

  1. Download wiringOP from Git:
git clone --branch next https://github.com/orangepi-xunlong/wiringOP.git
  1. Navigate to the wiringOP directory and run the installation command:
cd wiringOP
./build clean
./build
  1. Download the C script and save it to the directory of your choice.
git clone https://github.com/bastilmr/opi5-fan-control.git
  1. Compile the script using the following command:
gcc -o fan-control fan-control.c -lwiringPi

Or for binary fan control (no PWM):

gcc -o fan-control binary-fan-control.c -lwiringPi
  1. Make the script executable:
chmod +x fan-control
  1. Add the script to your crontab to run at boot using the following command:
crontab -e
  1. Add the following line to your crontab to run the script at boot:
@reboot /path/to/fan-control

Be sure to replace /path/to/ with the actual path to the directory where the script is located.

Configuration

The script is configured by default to control the fan speed based on the CPU temperature. However, you can customize the configuration to your needs by changing the following variables in the script:

  • FAN_PIN: The GPIO pin where the fan is connected.
  • CPU_TEMP_FILE: The file that contains the CPU temperature.
  • MIN_TEMP: The minimum CPU temperature at which the fan runs at the minimum speed.
  • MAX_TEMP: The maximum CPU temperature at which the fan runs at the maximum speed.
  • MIN_PWM: The minimum fan speed.
  • MAX_PWM: The maximum fan speed.

In this example, the fan was connected to the 5V, Ground, and GPIO4_A3 (UART0_TX_M2) Pin of the Orange Pi 5.

Note

This script has been successfully tested on an Orange Pi 5 and Orange Pi 5b. However, it should also work on other Orange Pi's.

opi5-fan-control's People

Contributors

bastilmr avatar tar-alex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

opi5-fan-control's Issues

undefined reference to `crypt' undefined reference to `pow'

orangepi@orangepi5:~/opi5-fan-control$ gcc -o fan-control fan-control.c -lwiringPi
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/11/../../../../lib/libwiringPi.so: undefined reference to `crypt'
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/11/../../../../lib/libwiringPi.so: undefined reference to `pow'
collect2: error: ld returned 1 exit status

I cloned the v0.2 version and seemed to install ok

orangepi@orangepi5:~/opi5-fan-control$ gpio readall
 +------+-----+----------+--------+---+   OPI5   +---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 |      |     |     3.3V |        |   |  1 || 2  |   |        | 5V       |     |      |
 |   47 |   0 |    SDA.5 |     IN | 1 |  3 || 4  |   |        | 5V       |     |      |
 |   46 |   1 |    SCL.5 |     IN | 1 |  5 || 6  |   |        | GND      |     |      |
 |   54 |   2 |    PWM15 |     IN | 1 |  7 || 8  | 0 | IN     | RXD.0    | 3   | 131  |
 |      |     |      GND |        |   |  9 || 10 | 0 | IN     | TXD.0    | 4   | 132  |
 |  138 |   5 |  CAN1_RX |     IN | 1 | 11 || 12 | 1 | IN     | CAN2_TX  | 6   | 29   |
 |  139 |   7 |  CAN1_TX |     IN | 1 | 13 || 14 |   |        | GND      |     |      |
 |   28 |   8 |  CAN2_RX |     IN | 1 | 15 || 16 | 1 | IN     | SDA.1    | 9   | 59   |
 |      |     |     3.3V |        |   | 17 || 18 | 1 | IN     | SCL.1    | 10  | 58   |
 |   49 |  11 | SPI4_TXD |     IN | 1 | 19 || 20 |   |        | GND      |     |      |
 |   48 |  12 | SPI4_RXD |     IN | 1 | 21 || 22 | 1 | IN     | GPIO2_D4 | 13  | 92   |
 |   50 |  14 | SPI4_CLK |     IN | 1 | 23 || 24 | 1 | IN     | SPI4_CS1 | 15  | 52   |
 |      |     |      GND |        |   | 25 || 26 | 1 | IN     | PWM1     | 16  | 35   |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+   OPI5   +---+--------+----------+-----+------+

Any idea on what the errors are as all new to me.

After a Google I tried gcc -o fan-control fan-control.c -lwiringPi -lcrypt -lm and worked

Add another varaible for below min temp PWM

In current state when temperature is above but close to MIN_TEMP and MIN_PWM is 0 fun is making noise as PWM value there would be too low for it to spin stable. I would suggest to add another macro, lets say PWM_BELOW_TEMP (default to 0) and set PWM to that value when temperature is below MIN_TEMP. This allow to set MIN_PWM to higher values, lets say 30% - which makes fan not to rotate when temperature below MIN_TYEMP but then instantly start with 30% and to avoid making noise and not to start.

unable to run fan-control in crontab

Hi, I have followed the instructions provided to install and run fan-control on an orangepi5. I'm very new in this domain and struggle to get crontab to run the program on startup/reboot.

To troubleshoot I then tried to run the program directly using
./fan-control
in the directory it was installed: /wiringOP/opi5-fan-control

I then get the following error:

orangepi@orangepi5:~/wiringOP/opi5-fan-control$ ./fan-control
wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: No such file or directory.
  Aborting your program because if it can not access the GPIO
  hardware then it most certianly won't work
  Try running with sudo?

Running the same command with sudo worked after giving the device password.

lastly here is my crontab command if ever I made a mistake on it:

@reboot /wiringOP/opi5-fan-control/fan-control

What I understand so far is that I need to run crontab with the "sudo" permission. But there is no mention of this in your instructions. Have I overlocked a crucial step ? How can I set things up so ./fan-control doesn't need "permissions" ?

Thank you !

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.