Jump to content

Rock 5C How to control PWM fan manually?


Go to solution Solved by bedna,

Recommended Posts

Posted

Hi everyone,

I have rock 5c with PWM fan. I want to control the fan speed manually. Running on Armbian 25.11.1 Noble.

Sorry if its obvious I am newbie to this 

  • Solution
Posted (edited)

Tried this?

https://gist.github.com/c0m4r/b3fea6342bcf5a1b25b608fc36100d68#pwm-fan-control

 

Ie: download the script and systemd service, edit the script to your liking (or try default) and activate the service.

As default It configures to user_space and checks temps every 10s.

 

https://raw.githubusercontent.com/c0m4r/radxa_rock5c_lite/refs/heads/main/usr/local/bin/rock5c_fan_pwm

##########################################################
# Radxa Rock 5C fan PWM control script
# Author: https:///github.com/c0m4r
# License: Public Domain
##########################################################

# PWM control path
PWM_PATH="/sys/devices/platform/pwm-fan/hwmon"

# Configuration
INTERVAL=10         # Temperature check interval (seconds)
FAN_OFF=1           # 1 = turn off fan below MIN_TEMP after cooldown, 0 = keep at min RPM
COOLDOWN=300        # time to wait before turning off the fan when FAN_OFF=1

# Critical temp protection
POWEROFF_ON_CRIT=1  # 1 = shutdown when the temperature reaches a critical value, 0 = disable
CRITICAL_TEMP=70    # Critical temperature (shutdown)

# PWM Values (proper)
SAFE_PWM_MIN=105    # Safe minimum PWM to keep fan spinning
PWM_LOW=125         # 45–50°C (~50% speed)
PWM_MID=165         # 50–55°C (~65% speed)
PWM_HIGH=200        # 55–60°C (~80% speed)
PWM_MAX=255         # >60°C (100% speed)

# PWM Values (temporary - use these instead of proper if the fan spins at max all the time)
#SAFE_PWM_MIN=50    # Safe minimum PWM to keep fan spinning
#PWM_LOW=60         # 45–50°C (~50% speed)
#PWM_MID=70         # 50–55°C (~65% speed)
#PWM_HIGH=80        # 55–60°C (~80% speed)
#PWM_MAX=255         # >60°C (100% speed)

# Constants (requires also changes in code)
MIN_TEMP=47         # Minimum temperature (PWM_MIN)
MAX_TEMP=60         # Maximum temperature (PWM_MAX)


# Set thermal policy
thermal_zones=$(ls -1 /sys/class/thermal | grep thermal_zone)

if [[ "$thermal_zones" ]]; then
  for i in /sys/class/thermal/thermal_zone*/policy ; do
    echo "user_space" > "$i"
  done
else
  echo "No sensors found, check kernel support, setting fan to high for now!"
  echo $PWM_HIGH > ${PWM_PATH}/hwmon*/pwm1
  exit 1
fi

# Set PWM_MIN based on FAN_OFF mode
if [ "$FAN_OFF" -eq 1 ]; then
  PWM_MIN=0 # Allow fan to turn off after cooldown
else
  PWM_MIN=$SAFE_PWM_MIN # Keep fan at minimal safe RPM all the time
fi

# Validate PWM path
if [ ! -d "$PWM_PATH" ]; then
  echo "Error: PWM control file not found: $PWM_PATH"
  exit 1
fi

# Initialize variables
current_pwm=$(cat ${PWM_PATH}/hwmon*/pwm1) # Start at current PWM
last_high_temp_time=0 # Track last high temp for cooldown
echo "Initializing fan at PWM $current_pwm"
echo "$current_pwm" > ${PWM_PATH}/hwmon*/pwm1

# Main loop
while true; do
  for i in /sys/class/thermal/thermal_zone*/policy ; do
    echo "user_space" > "$i"
  done

<snip>

 

Edited by bedna

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...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines