[Solved] Change fan speed XU4

Since the change from jessie to stretch a few changes have been noticed and easily ignored. The big one I am having an issue with is setting my fan speed.

sudo nano ../etc/rc.local


(add the following lines before "exit 0")


for file in /sys/devices/odroid_fan.*/temp_levels
do
 echo '35 40 55' > "$file"
done

That used to work but under /sys/devices there is no odroid_fan.14 any more. How do I adjust my fan speed now?

edit: when I say fan speed what I mean is the temperatures where the fan speeds increase. I don’t like it getting to 95’ C before the fan actually puts effort into running. By that stage it is already causing a lot of damage and usually crashes due to heat.

Shanther
It appears that I wrote some script to adjust fan speed: https://raw.githubusercontent.com/Fourdee/DietPi/dietpi-set_cpu_fan/dietpi/func/dietpi-set_cpu_fan

This was started work with XU4 fan interface: https://github.com/Fourdee/DietPi/issues/1818

Actually we wanted to add support for more devices, but it appears that the variety of CPU fan (PWM) control APIs is veeery large. Huge work, too much to achieve that currently. For this reason we did not yet implement it into DietPi, as long as XU4 is supported only. But as it fits perfect in your case, give it a try :sunglasses:.

Interesting that you use a different interface than me: /sys/devices/odroid_fan.*/temp_levels
I used according to the guide: /sys/devices/virtual/thermal/thermal_zone/trip_point_[0-2]_temp*
Perhaps the XU4 has different APIs for that? Was the same with some x86 PC, so could be.

So as far as I understood the API:

  • /sys/devices/odroid_fan.*/temp_levels respectively /sys/devices/virtual/thermal/thermal_zone/trip_point_[0-2]_temp* is used to define the three temperature trip points. If they are reached, the CPU fan speed is increased to the desired speed, that you can configure for each trip point.
  • Use /sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed to apply the related trip fan speeds via values from 0 (0% PWM) to 255 (100% PWM). E.g.
echo '0 120 180 240' /sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed

First value is for temps below first temp point, second value after first temp point, third after second temp point, fourth after third temp point.

  • /sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic btw. needs to be value “1”, but that should be default.

But I would like, if you test my script. Would be great if it could be debugged at least to work well with XU4. Also everything is well explained within whiptail GUI. To try it out:

wget https://raw.githubusercontent.com/Fourdee/DietPi/dietpi-set_cpu_fan/dietpi/func/dietpi-set_cpu_fan -O /DietPi/dietpi/func/dietpi-set_cpu_fan
chmod +x /DietPi/dietpi/func/dietpi-set_cpu_fan
sed -i '\|/DietPi/dietpi/func/dietpi-set_cpu|a\\t\t/DietPi/dietpi/func/dietpi-set_cpu_fan 1 \&|' /DietPi/dietpi/preboot

This installs the script alls runs (reapplies) fan settings on boot.
To configure it: /DietPi/dietpi/func/dietpi-set_cpu_fan

I don’t understand most of that code. That’s why what I had was a single line. I use dietpi so I don’t need to learn any of the coding. I can’t even read all of what you wrote. I did notice 1 thing though.

So as far as I understood the API: •/sys/devices/odroid_fan./temp_levels respectively /sys/devices/virtual/thermal/thermal_zone/trip_point_[0-2]_temp is used to define the three temperature trip points. If they are reached, the CPU fan speed is increased to the desired speed, that you can configure for each trip point.
•Use /sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed to apply the related trip fan speeds via values from 0 (0% PWM) to 255 (100% PWM). E.g.

In the above you said a folder in /sys/devices/ called “odroid_fan.*” should exist. No folder with that name exists there. That’s what my biggest issue was. Almost every solution I have found over time involved going into that folder and adjusting something there.

As for testing your script, if something goes wrong I can’t do anything to fix it as I have such little knowledge unfortunately.

Sorry, I didn’t read your post carefully enough. Actually I didn’t find some hint about /sys/devices/odroid_fan.*/temp_levels when I wrote and did research for the script.
As said, I found and use /sys/devices/virtual/thermal/thermal_zone/trip_point_*_temp* to do exactly what you aimed to do with your code line.
Perhaps the API changed in the past and the file got replaced.

Lets check, if the (new) API really works on your C2 and also enable you to stay with your rc.local entry, but fixed. Please paste the output of the following terminal commands:

ls -al /sys/devices/virtual/thermal/thermal_zone*/trip_point_*_temp
cat /sys/devices/virtual/thermal/thermal_zone*/trip_point_*_temp

I don’t have a C2. I have an XU4. Mine has a built in fan and the C2 uses a USB fan. Will that affect the script? I imagine it would. if not I will try it but if it doesn’t work I won’t be able to provide logs or anything as I don’t know enough about Linux to find them and would have to format if it stops the device from booting.

Times like this I wish you guys had something on your website where people can buy you devices to help you work on them. I would be ticking the XU4 for someone as it is slightly different to the XU3 but so damn handy.

Ah sorry, I meant XU4 with native fan port. Jep the script/method should work with XU4. USB fans cannot be controlled directly. That would need an additional board to enable PWM or similar and e.g. some custom GPIO based control API.

Hehe, Fourdee at least has all those devices for testing and development.
I was quite often offered to get the one or the other SBC (have just RPi2 here for own little production server), but spare time is already more than filled with bash coding, that I can in most cases test well on DietPi VMs.

So the limiting factor ist mostly not the devices (donations are possible, manufacturer also sometimes send them), but mostly the spare time/man power :roll_eyes:.

ok…sweet. Now the stupid question. What do I even do with that script? My coding skills are beyond lacking. Imagine someone with enough knowledge to google code but no clue to what to do with it or what it does.

Also does that script have the temp set at the ones I have or do I need to change something?

I am very worried as I am now 10 hours into the install and really don’t want to restart that. I am now renaming everything that didn’t auto rename in Plex.

Fix by MichaIng

Instead of using:

for file in /sys/devices/odroid_fan.*/temp_levels
do
 echo '35 40 55' > "$file"
done

Use this instead:

for file in /sys/devices/virtual/thermal/thermal_zone*
do
 echo 35 > $file/trip_point_0_temp
 echo 40 > $file/trip_point_1_temp
 echo 55 > $file/trip_point_2_temp
done

Just like normal put at the bottom (before “end”) of:

sudo nano ../etc/rc.local