OrangePi 4 temperature controlled PWM fan


Recommended Posts

Hi all,

 

So if a lot of you maybe know is a heatsink and fan  a must for the OrangePi 4. With my temporarly installed fan makes a lot of noise i maked yesterday the step to order a Noctua NF-A4x20 5V PWM. The price was arround €17,- not the cheapest but te reviews are amazing.

 

Even on full speed its a lot more silence then the 20x20 mini fan but with a good air flow. But as you could read did i choose for a PWM variant so i could control the rpm´s with a PWM GPIO pin. And amazingly it did work! I have the PWM pin connected to pin 7 of the OrangePi 4.

 

Commands to start pwm for the first time:

 

cd /sys/class/pwm/pwmchip1/
echo 0 > export
  
echo 1000000 > pwmchip1/pwm0/period

echo 500000 > pwm0/duty_cycle
  
#and with this step the fan goes on a lower speed
  
echo 1 > pwm0/enable

#and back on full speed without PWM

echo 0 > pwm0/enable

 

So it´s really nice. And i found a nice script for the Nanopi M4 with also a RK3399 chip from @mar0ni in this topic

 

To make it complete i paste also here the script from @mar0n

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

Just now, haajee said:

Hi all,

 

So if a lot of you maybe know is a heatsink and fan  a must for the OrangePi 4. With my temporarly installed fan makes a lot of noise i maked yesterday the step to order a Noctua NF-A4x20 5V PWM. The price was arround €17,- not the cheapest but te reviews are amazing.

 

Even on full speed its a lot more silence then the 20x20 mini fan but with a good air flow. But as you could read did i choose for a PWM variant so i could control the rpm´s with a PWM GPIO pin. And amazingly it did work! I have the PWM pin connected to pin 7 of the OrangePi 4.

 

Commands to start pwm for the first time:

 


cd /sys/class/pwm/pwmchip1/
echo 0 > export
  
echo 1000000 > pwmchip1/pwm0/period

echo 500000 > pwm0/duty_cycle
  
#and with this step the fan goes on a lower speed
  
echo 1 > pwm0/enable

#and back on full speed without PWM

echo 0 > pwm0/enable

 

So it´s really nice. And i found a nice script for the Nanopi M4 with also a RK3399 chip from @mar0ni in this topic

 

To make it complete i paste also here the script from @mar0ni

 


#!/bin/bash

if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip1/pwm0 ];
do
    sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

# max speed run 5s
echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
sleep 5
echo 49994 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

declare -a CpuTemps=(75000 63000 58000 52000 48000 0)
declare -a PwmDutyCycles=(25000 37000 48300 49250 49300 49994)

while true
do
	temp=$(cat /sys/class/thermal/thermal_zone0/temp)
	for i in 0 1 2 3 4 5; do
		if [ $temp -gt ${CpuTemps[$i]} ]; then
			DUTY=${PwmDutyCycles[$i]}
			echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";
			#echo "temp: $temp, target: ${CpuTemps[$i]}, duty: $DUTY"
			break		
		fi
	done
	sleep 2s;
done

 

I saved the file in my home dir as pwm-fan.sh and run it as administrator with

bash ./pwm-fan.sh

And the fan spins up full speed but after that it stops running. Even when the temperature is over the 30 degrees celsius. I have changed 48000 in the above script to 30000. So i think there is also something else to change but i have no idea what. Who could help me? :)

Link to post
Share on other sites
On 4/19/2020 at 6:25 AM, VyacheslavS said:

@haajee,

I have for some reason does not work, there is no signal from the 7 pin.

Kernel 5.6.3 Buster.

What else do I need to do to make it work?

 

Oh sorry i didn´t saw your post. My fan script is now:

 

#!/bin/bash

if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip1/pwm0 ];
do
    sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

# max speed run 60s
echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
sleep 5
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

declare -a CpuTemps=(45000 40000 38000 30000 28000 0)
declare -a PwmDutyCycles=(1000 5000 10000 15000 30000)

while true
do
        temp=$(cat /sys/class/thermal/thermal_zone0/temp)
        for i in 0 1 2 3 4 5; do
                if [ $temp -gt ${CpuTemps[$i]} ]; then
                        DUTY=${PwmDutyCycles[$i]}
                        echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";
                        echo "temp: $temp, target: ${CpuTemps[$i]}, duty: $DUTY"
                        break
                fi
        done
        sleep 1s;
done

Do you see something if you go to /sys/class/pwm/pwmchip1?  And do you have installed wiring orangepi from:  https://github.com/orangepi-xunlong/wiringOP ?? what does the command gpio readall shows?

Link to post
Share on other sites
On 7/9/2020 at 2:45 AM, haajee said:

what does the command gpio readall shows?

$ gpio readall shows
 +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | GPIO |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |  1 || 2  |   |      | 5V       |     |      |
 |   64 |   0 | I2C2_SDA |   IN | 0 |  3 || 4  |   |      | 5V       |     |      |
 |   65 |   1 | I2C2_SCL |   IN | 0 |  5 || 6  |   |      | GND      |     |      |
 |  150 |   2 |     PWM1 | ALT2 | 1 |  7 || 8  | 1 | ALT2 | I2C3_SCL | 3   | 145  |
 |      |     |      GND |      |   |  9 || 10 | 1 | ALT2 | I2C3_SDA | 4   | 144  |
 |   33 |   5 | GPIO1_A1 |   IN | 0 | 11 || 12 | 1 | IN   | GPIO1_C2 | 6   | 50   |
 |   35 |   7 | GPIO1_A3 |  OUT | 1 | 13 || 14 |   |      | GND      |     |      |
 |   92 |   8 | GPIO2_D4 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO1_C6 | 9   | 54   |
 |      |     |     3.3V |      |   | 17 || 18 | 0 | IN   | GPIO1_C7 | 10  | 55   |
 |   40 |  11 | SPI1_TXD | ALT3 | 0 | 19 || 20 |   |      | GND      |     |      |
 |   39 |  12 | SPI1_RXD | ALT3 | 1 | 21 || 22 | 0 | IN   | GPIO1_D0 | 13  | 56   |
 |   41 |  14 | SPI1_CLK | ALT3 | 1 | 23 || 24 | 1 | ALT3 | SPI1_CS  | 15  | 42   |
 |      |     |      GND |      |   | 25 || 26 | 0 | IN   | GPIO4_C5 | 16  | 149  |
 |   64 |  17 | I2C2_SDA |   IN | 0 | 27 || 28 | 0 | IN   | I2C2_SCL | 18  | 65   |
 |      |     |  I2S0_RX |      |   | 29 || 30 |   |      | GND      |     |      |
 |      |     |  I2S0_TX |      |   | 31 || 32 |   |      | I2S_CLK  |     |      |
 |      |     | I2S0_SCK |      |   | 33 || 34 |   |      | GND      |     |      |
 |      |     | I2S0_SI0 |      |   | 35 || 36 |   |      | I2S0_SO0 |     |      |
 |      |     | I2S0_SI1 |      |   | 37 || 38 |   |      | I2S0_SI2 |     |      |
 |      |     |      GND |      |   | 39 || 40 |   |      | I2S0_SI3 |     |      |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | GPIO |
 +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+

 

On 7/9/2020 at 2:45 AM, haajee said:

Do you see something if you go to /sys/class/pwm/pwmchip1?

$ ls /sys/class/pwm/pwmchip1
device  export  npwm  power  subsystem  uevent  unexport

I don't have a pwm0 folder.

 

On 7/9/2020 at 2:45 AM, haajee said:

And do you have installed wiring orangepi from:  https://github.com/orangepi-xunlong/wiringOP ??

Yes.

Link to post
Share on other sites

@haajee , This is a problem with my cooler.  It starts rotating with 3.3 V. If the tension is less, then silence.

I took voltage measurements from 7 pin.  The voltage on this pin is: min=1.0 V, max=2.9 V.

Tell me please did you connect Noctua NF-A4x20 5V PWM directly or via MOSFET?

In Noctua cooler with 4 pins or 3 pins?

Link to post
Share on other sites
On 7/11/2020 at 2:25 PM, VyacheslavS said:

@haajee , This is a problem with my cooler.  It starts rotating with 3.3 V. If the tension is less, then silence.

I took voltage measurements from 7 pin.  The voltage on this pin is: min=1.0 V, max=2.9 V.

Tell me please did you connect Noctua NF-A4x20 5V PWM directly or via MOSFET?

In Noctua cooler with 4 pins or 3 pins?

 

Very sorry for my always late anwsers. I have my nf-a4x20-5v-pwm directly connected to gnd and 5V pin on the orange pi. The PWM pin do i have connected to pin 7. The RPM pin did i have not connected. I have bought the Noctua in a local internet store for arround €12,- without shipping. The fan is also on full speed so much silent than al the fans i got. I am a really Fanboy now of Noctua ;) I could advice you to buy. :) more specifications are here https://noctua.at/en/products/fan/nf-a4x20-5v-pwm

 

All what you post is exactly the same what i have... I don´t see a different.

 

Link to post
Share on other sites
On 8/2/2020 at 3:32 AM, haajee said:

I have bought the Noctua in a local internet store for arround €12,- without shipping.

 

I also bought the same one, about 15 Euros.  I configured the script and now it starts to rotate from +35, the rotation speed is floating. The maximum spin speed starts at +60 . This cooler is really quiet and worth it money.

Link to post
Share on other sites

Another solution to avoid noise and fan management for orange pi 4 is to use a big heatsink (fanless solution):

 

Orange Pi 4 Heatsink

 

I tried it and it works well.

 

The temperature can rise to 85°C in peak (and 82°C in average) when I tried to stress the cpu with benchmark or with high resolution youtube video, but I never stayed stuck due to a overheat.

In normal use, I have more something between 58 to 65 °C.

Link to post
Share on other sites

My device is only equipped with this tiny cooling set:

Spoiler

cooling-set.jpg.da9d3d4d8c43da51a990b00191fe967b.jpg

Even though all six cores run at 100% load, the fan only runs at full speed for two occasions:

Spoiler

tmon-log.thumb.png.dbd7171871b9e87d2edaaa76c9ff7156.png

Frequency scaling and DVFS haven't even begun yet. The kernel is handling the thermal system, no user space involved. Maybe time to collect tmon's log and investigate how the thermal system is performing.

Link to post
Share on other sites
On 8/8/2020 at 11:47 AM, firedgje said:

Another solution to avoid noise and fan management for orange pi 4 is to use a big heatsink (fanless solution):

 

Orange Pi 4 Heatsink

 

I tried it and it works well.

 

The temperature can rise to 85°C in peak (and 82°C in average) when I tried to stress the cpu with benchmark or with high resolution youtube video, but I never stayed stuck due to a overheat.

In normal use, I have more something between 58 to 65 °C.

 

IMHO is 85 celsius really hot. I don´t also know how a big themalpad could work. Is the heatsink warm when you run?

 

On 8/3/2020 at 2:04 PM, VyacheslavS said:

 

I also bought the same one, about 15 Euros.  I configured the script and now it starts to rotate from +35, the rotation speed is floating. The maximum spin speed starts at +60 . This cooler is really quiet and worth it money.

 

Mine have i running really slow and the temperature is arround 32 degrees on normal day with normal load. Full speed about 50 degrees. But i need to say that i have also a heatsink on the CPU from an old Fritzbox router. But even on fullspeed is the fan really quiet and you need to listen very well to here it run. In my opinion is 15 euros a really good deal when i compare with a lot of noisie fans i have. The only problem is that the fan is a little bit bigger than the fan opening of the Geekworm case... So i din´t have the original cover on the case...

 

temperatuur-laatste-maan.thumb.jpeg.681e4f8d8484fd9b70a60660060cc496.jpeg

Link to post
Share on other sites
On 8/9/2020 at 10:06 PM, haajee said:

 

IMHO is 85 celsius really hot. I don´t also know how a big themalpad could work. Is the heatsink warm when you run?

Yes, the heatsink could be warm. But as I said globally always around 82°C with all cpus at 100%, (and decrease quickly when I stop). I think the processor limit ~85 °C.

On 8/9/2020 at 10:06 PM, haajee said:

 

 

Mine have i running really slow and the temperature is arround 32 degrees on normal day with normal load. Full speed about 50 degrees. But i need to say that i have also a heatsink on the CPU from an old Fritzbox router. But even on fullspeed is the fan really quiet and you need to listen very well to here it run. In my opinion is 15 euros a really good deal when i compare with a lot of noisie fans i have. The only problem is that the fan is a little bit bigger than the fan opening of the Geekworm case... So i din´t have the original cover on the case...

 

temperatuur-laatste-maan.thumb.jpeg.681e4f8d8484fd9b70a60660060cc496.jpeg

I tested previously another solution with a little heatsink and a fan, the temperature was also around 50°C. It is a personal choice to change in order to have no noise, because I use it as pc and as media center.

Link to post
Share on other sites
On 8/11/2020 at 9:04 PM, firedgje said:

Yes, the heatsink could be warm. But as I said globally always around 82°C with all cpus at 100%, (and decrease quickly when I stop). I think the processor limit ~85 °C.

I tested previously another solution with a little heatsink and a fan, the temperature was also around 50°C. It is a personal choice to change in order to have no noise, because I use it as pc and as media center.

I did a more complete temperature  test with cpu sysbench during a long time:

 

Temperature Test
 
N°: T0°C T1°C
1:  79°C 79°C
2:  82°C 83°C
3:  83°C 83°C
4:  83°C 82°C
5:  83°C 83°C
6:  82°C 82°C
7:  83°C 83°C
8:  83°C 83°C
9:  83°C 83°C
10:  83°C 83°C
11:  83°C 83°C
12:  83°C 83°C
13:  83°C 83°C
14:  82°C 83°C
15:  83°C 83°C
16:  83°C 83°C
17:  83°C 83°C
18:  83°C 83°C
19:  82°C 83°C
20:  83°C 83°C

 

The temperature never exceeds 83°C.

Link to post
Share on other sites
2 hours ago, firedgje said:

I did a more complete temperature  test with cpu sysbench

Out of curiosity, I'm interested in how your thermal system works during the test.
Can you by chance provide a tmon.log?
To collect one, start "tmon -dl", perform your thermal stress test and after round about 15 minutes kill the tmon process.
Now post the resulting /var/tmp/tmon.log.

Link to post
Share on other sites
On 8/15/2020 at 5:57 PM, usual user said:

Out of curiosity, I'm interested in how your thermal system works during the test.
Can you by chance provide a tmon.log?
To collect one, start "tmon -dl", perform your thermal stress test and after round about 15 minutes kill the tmon process.
Now post the resulting /var/tmp/tmon.log.

Sorry, tmon package seems not to be available.... but I can give you my simple test script:

 

#!/bin/bash
clear

echo "Temperature Test"
echo " "
echo "N°: T0°C T1°C"

for i in {1..50}
do
    a=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)
    b=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone1/temp) / 1000)
    echo "$i:  $a°C $b°C"
    sysbench cpu --cpu-max-prime=1000000 --threads=$(nproc) run > /dev/null
done

a=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)
b=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone1/temp) / 1000)
echo "$i:  $a°C $b°C"

exit 0

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...