<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.linuxsa.org/index.php?action=history&amp;feed=atom&amp;title=%E6%A0%91%E8%8E%93%E6%B4%BE_%E6%A0%B9%E6%8D%AE_CPU_%E6%B8%A9%E5%BA%A6%E6%8E%A7%E5%88%B6%E9%A3%8E%E6%89%87%E8%B5%B7%E5%81%9C</id>
	<title>树莓派 根据 CPU 温度控制风扇起停 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.linuxsa.org/index.php?action=history&amp;feed=atom&amp;title=%E6%A0%91%E8%8E%93%E6%B4%BE_%E6%A0%B9%E6%8D%AE_CPU_%E6%B8%A9%E5%BA%A6%E6%8E%A7%E5%88%B6%E9%A3%8E%E6%89%87%E8%B5%B7%E5%81%9C"/>
	<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=%E6%A0%91%E8%8E%93%E6%B4%BE_%E6%A0%B9%E6%8D%AE_CPU_%E6%B8%A9%E5%BA%A6%E6%8E%A7%E5%88%B6%E9%A3%8E%E6%89%87%E8%B5%B7%E5%81%9C&amp;action=history"/>
	<updated>2026-04-19T16:17:39Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.linuxsa.org/index.php?title=%E6%A0%91%E8%8E%93%E6%B4%BE_%E6%A0%B9%E6%8D%AE_CPU_%E6%B8%A9%E5%BA%A6%E6%8E%A7%E5%88%B6%E9%A3%8E%E6%89%87%E8%B5%B7%E5%81%9C&amp;diff=1331&amp;oldid=prev</id>
		<title>2022年1月4日 (二) 11:18 Evan</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=%E6%A0%91%E8%8E%93%E6%B4%BE_%E6%A0%B9%E6%8D%AE_CPU_%E6%B8%A9%E5%BA%A6%E6%8E%A7%E5%88%B6%E9%A3%8E%E6%89%87%E8%B5%B7%E5%81%9C&amp;diff=1331&amp;oldid=prev"/>
		<updated>2022-01-04T11:18:35Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[category:raspberrybi]]  [[category:raspberrypi]] &lt;br /&gt;
=Q=&lt;br /&gt;
风扇声音非常大  晚上睡觉时就烦死了&lt;br /&gt;
&lt;br /&gt;
=R=&lt;br /&gt;
&lt;br /&gt;
[http://blog.lxx1.com/2842 树莓派使用三极管实现温度控制风扇]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://testerhome.com/topics/8068&lt;br /&gt;
&lt;br /&gt;
https://blog.csdn.net/qq_15947947/article/details/79637718&lt;br /&gt;
&lt;br /&gt;
http://bbs.elecfans.com/forum.php?mod=viewthread&amp;amp;tid=1117101&amp;amp;extra=page=2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
我用了，连续开机半年，没问题。一天散热片掉了(我把派竖着放了)，几天后，派挂了。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1.拆开风扇中间的胶，加机油&lt;br /&gt;
&lt;br /&gt;
2.垫块海棉 在壳最下面&lt;br /&gt;
&lt;br /&gt;
散热片&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
try:&lt;br /&gt;
    import RPi.GPIO as GPIO&lt;br /&gt;
except RuntimeError:&lt;br /&gt;
    print(&amp;quot;Error importing RPi.GPIO!  This is probably because you need superuser privileges.  You can achieve this by using &amp;#039;sudo&amp;#039; to run your script&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def cpu_temp():&lt;br /&gt;
    with open(&amp;quot;/sys/class/thermal/thermal_zone0/temp&amp;quot;, &amp;#039;r&amp;#039;) as f:&lt;br /&gt;
        return float(f.read())/1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    channel = 18&lt;br /&gt;
    GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
    GPIO.setwarnings(False)&lt;br /&gt;
&lt;br /&gt;
    # close air fan first&lt;br /&gt;
    GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)&lt;br /&gt;
    is_close = True&lt;br /&gt;
    while True:&lt;br /&gt;
        temp = cpu_temp()&lt;br /&gt;
        if is_close:&lt;br /&gt;
            if temp &amp;gt; 45.0:&lt;br /&gt;
                print time.ctime(), temp, &amp;#039;open air fan&amp;#039;&lt;br /&gt;
                GPIO.output(channel, GPIO.HIGH)&lt;br /&gt;
                is_close = False&lt;br /&gt;
        else:&lt;br /&gt;
            if temp &amp;lt; 38.0:&lt;br /&gt;
                print time.ctime(), temp, &amp;#039;close air fan&amp;#039;&lt;br /&gt;
                GPIO.output(channel, GPIO.LOW)&lt;br /&gt;
                is_close = True&lt;br /&gt;
&lt;br /&gt;
        time.sleep(2.0)&lt;br /&gt;
        print time.ctime(), temp&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://testerhome.com/topics/8068&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
鄙人最终就使用了三极管方案，使用最短，最简单的接线方法，完全藏匿起来。&lt;br /&gt;
代码：&lt;br /&gt;
代码是最简单的代码，仅根据温度控制转与不转，可以直接复制使用，&lt;br /&gt;
&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
import time&lt;br /&gt;
import commands&lt;br /&gt;
&lt;br /&gt;
T_HIGH = 45&lt;br /&gt;
T_LOW = 35&lt;br /&gt;
fan_pin = 12&lt;br /&gt;
GPIO.setwarnings(False)&lt;br /&gt;
GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
GPIO.setup(fan_pin, GPIO.OUT)&lt;br /&gt;
&lt;br /&gt;
def get_gpu_temp():&lt;br /&gt;
    gpu_temp = commands.getoutput( &amp;#039;/opt/vc/bin/vcgencmd measure_temp&amp;#039; ).replace( &amp;#039;temp=&amp;#039;, &amp;#039;&amp;#039; ).replace( &amp;#039;\&amp;#039;C&amp;#039;, &amp;#039;&amp;#039; )&lt;br /&gt;
    return  float(gpu_temp)&lt;br /&gt;
&lt;br /&gt;
while 1:&lt;br /&gt;
    gpu_temp_loop = get_gpu_temp()&lt;br /&gt;
    print &amp;#039;GPU temp:&amp;#039;, gpu_temp_loop,&amp;#039;C&amp;#039;&lt;br /&gt;
    if gpu_temp_loop &amp;gt; T_HIGH:&lt;br /&gt;
        GPIO.output(fan_pin, 1)&lt;br /&gt;
    elif gpu_temp_loop &amp;lt; T_LOW:&lt;br /&gt;
        GPIO.output(fan_pin, 0)&lt;br /&gt;
    time.sleep(5)&lt;br /&gt;
&lt;br /&gt;
复制时注意分割线，另存为python文件即可（如pi2_fan.py）&lt;br /&gt;
运行就是直接python pi2_fan.py&lt;br /&gt;
如果想随机启动就加到rc.local里，这个可以搜一下就知道。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=see also=&lt;br /&gt;
&lt;br /&gt;
[http://bbs.elecfans.com/forum.php?mod=viewthread&amp;amp;tid=1117101&amp;amp;extra=page=2 三种树莓派温度控制风扇方案整理]&lt;br /&gt;
&lt;br /&gt;
[http://tieba.baidu.com/p/4517879579 为什么买回来的风扇都他不是静音]&lt;br /&gt;
&lt;br /&gt;
[https://jingyan.baidu.com/article/59a015e362bd45f795886559.html 树莓派3散热片的安装]&lt;br /&gt;
&lt;br /&gt;
[https://testerhome.com/topics/14790  厨房直饮水净水器 DIY 安装记录]&lt;/div&gt;</summary>
		<author><name>Evan</name></author>
	</entry>
</feed>