由于Nano散热差时,会造成宕机等问题,所以必须配上风扇,PWM最佳
手动设置
PWM范围:0 - 255
最小0即不转,255为最大转速
sudo sh -c 'echo 255 > /sys/devices/pwm-fan/target_pwm'
运行后,若风扇引脚正确,则此时风扇会以最大速度运行
自动调速
- 编写自动运行的py文件
#!/usr/bin/env python
import os
# import commands
# from the path of this pattern
path = '/sys/kernel/debug/soctherm/{dev}/temp'
# get the temperature from following sensors
dev = ['cpu', 'gpu', 'mem', 'pll']
# the fan PWM factor is 0 ~ 255, make 10 as the min, 255 as the max
# the fan speed will be sliding from 10% ~ 100% according to the temperature
# the greater, the cooler yet noisier, this script will balance it
MIN=80
MAX=255
RANGE=MAX-MIN
# the target file to write PWM factor to control the fan speed
TARGET_PWM = '/sys/devices/pwm-fan/target_pwm'
# defined the lowest temperature (Celsius), fan speed at MIN if temp lower then this
LOWEST=38.0
# defined the highest temperature (Celsius), fan speed at MAX if temp higher then this
HIGHEST=60.0
# the temp at range between HIGHEST and LOWEST, the fan speed is auto ajusted
# to balance the cool and the quiet
TMP_RANGE=HIGHEST-LOWEST
def getTmpFromFile(p):
'''get temp value in Celsius from a file'''
with open(p, 'r') as f:
x = f.read()
y = int(x)/1000.0
return y
def getSpeedByTemp(temp):
'''calculate a fan speed pwm factor from a temperature in Celsius'''
if temp<=LOWEST-5:
return 0
if temp<=LOWEST:
return MIN
if temp>=HIGHEST:
return MAX
rate = (temp-LOWEST)/TMP_RANGE
return MIN+int(RANGE*rate) if rate<1.0 else MAX
def setSpeed(pwm):
'''write target PWM factor to the target file to set fan speed'''
with open(TARGET_PWM, 'w') as f:
f.write(str(pwm))
# get max temperature from all sensors
max_temp = max(map(getTmpFromFile, map(lambda x: path.format(dev=x), dev)))
print(max_temp)
# calculate the target fan pwm factor
target_speed = getSpeedByTemp(max_temp)
print(target_speed)
# set to target file to take effect
setSpeed(target_speed)
- 开机自启,编写/etc/rc.local文件如下
#!/bin/bash
sudo /usr/bin/jetson_clocks
nohup sudo watch -n 20 '/usr/bin/python /root/adj_fan_pwm.py > /tmp/fan_pwm_log.log' &
即每20秒运行一次,其中/root/adj_fan_pwm.py 记为上面到py文件,并将运行的log保存到/tmp/fan_pwm_log.log
实时观察状态:jtop
- 创建rc-local.service文件
sudo vi /etc/systemd/system/rc-local.service
- 复制以下内容到rc-local.service文件
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
- 设置rc.local的权限
sudo chmod +x /etc/rc.local
- 启动服务
sudo systemctl enable rc-local
- 开启服务和查看状态
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service