How to control a PWM fan depending on CPU temperature on a OrangePi Zero (H2+ / H3) directly from the harware pwm pin (without a transistor, diode and resistor)? The current settings keeps the temperature below 50 degrees Celsius.
This solution requires Python - best with V 3.x or later. All examples are done with V 3.7
This was developed and tested on an OrangePi Zero. Most likely it will work on any H2+ and H3 chip solutions. The only thing to bare in mind is that you need to use PWM0 pin. On the OPi Zero (or on PC+) board this is the middle pin of the Debug TTL UART pins (the tree pins that stand alone next to the ethernet port).
# sudo apt-get update && sudo apt-get dist-upgrade -y
# python3 --version
-->shows actual installed version(s)
# sudo apt-get install python3.7
-->installs Python3.7
The two most crucial third-party Python packages are setuptools and pip.
# command -v pip3
-->see if PIP for Python3 is installed
Edit /boot/armbianEnv.txt and add new line: overlays=pwm
# cd /boot
# nano armbianEnv.txt
--> insert new line with overlays=pwm
Exit Nano with ControlX, y and Enter
# sudo reboot
-->reboot the OPi
# sudo pip3 install --upgrade OPi.GPIO
More info about OPi.GPIO is here: https://opi-gpio.readthedocs.io and here: https://github.com/rm-hull/OPi.GPIO
# cd /root
# git clone https://github.com/xpertsavenue/WiringOP-Zero.git
# cd WiringOP-Zero
# chmod +x ./build
# sudo ./build
Test if successful:
# gpio readall
More info about WiringOP-Zero is here: https://github.com/xpertsavenue/WiringOP-Zero.
In my case I have bought a nocuta NF-A4x10 5V PWM fan https://noctua.at/en/products/fan/nf-a4x10-5v-pwm. Excellent piece of work.
Connect:
YELLOW (VIN) to physical pin 4 (5V)
BLACK (GND) to physical pin 6 (GND)
BLUE (PWM) to middle pin of Debug TTL UART pins (3 standalone pins next to the Ethernet plug)
GREEN (RPM) will NOT be connected
Credits for this goes to https://www.instructables.com/PWM-Regulated-Fan-Based-on-CPU-Temperature-for-Ras/. To run the program automatically at startup, just use the bash script and autolaunch this bash script at startup within rc.local.
Copy launch_fan_ctrl.sh and fan_ctrl.py into /home (use FileZilla or similar)
Edit the /etc/rc.local file and add a new line before the "exit 0": sudo sh '/home/launch_fan_ctrl.sh':
# nano /etc/rc.local
add sudo sh '/home/launch_fan_ctrl.sh' as a new line before exit 0
Exit Nano with ControlX, y and Enter
# sudo reboot