散热片安装与风扇接线方法/ 和自动温控方法
查看:34835   回复:0   发布于2019-05-17 12:36:42
树莓派3B+的发热量要远远高于树莓派2和树莓派3,可以在参考下树莓派4B和树莓派3B+的对比,4B发热量更在增加了20%左右

Image


树莓派可24小时开机,耗电非常少。然而发热严重,主板超过70°会导致自动关机,给主板做好散热很有必要。


查询树莓派CPU温度命令:

vcgencmd measure_temp


Image



一:散热片方案(贴散热片)


树莓派3代贴法:

ImageImage


树莓派4B贴法:

Image



二:安装风扇方案


风扇红色线是正极,黑色线是负极。 接线时红色线应插到5V引脚上,黑色线应插到针脚GND上。 请参考下面引脚图。


风扇的LOGO标签是出风口,可以将风扇LOGO对着芯片吹风, 也可以将风扇LOGO朝外,这样也能将主板热量吸走排出去。具体装法可以自定

ImageImage


三:DIY温控启停风扇

这里讲一个DIY方案,可以根据CPU温度自动控制风扇起停的方案。通过树莓派GPIO来控制,但树莓派是GPIO自身输出电流很低,无法直接带动风扇,所以还需要一个三极管来放大电流。 我们这里采用型号是S9012PNP。

Image

接线方法:

三极管的E接树莓派5v引脚,B接GPIO口(建议用21号口,主板最右下方),C接风扇的负极(风扇黑线)。B口建议再加上一个1K的电阻,防止三极管过热。


Image

温度传感器是CPU内置的,通过读取系统的/sys/class/thermal/thermal_zone0/temp文件就可以获取到温度。用Python代码就是

def cpu_temp():
with open("/sys/class/thermal/thermal_zone0/temp", 'r') as f:
return float(f.read())/1000

而GPIO口的电压高低可以通过python的RPi.GPIO库来控制。比如想设置IO-21号口为高电平,代码是

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, GPIO.HIGH)

整合起来的代码如下

import sys
import time
try:
import RPi.GPIO as GPIO
except RuntimeError:
print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")


def cpu_temp():
with open("/sys/class/thermal/thermal_zone0/temp", 'r') as f:
return float(f.read())/1000


def main():
channel = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

# close air fan first
GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)
is_close = True
while True:
temp = cpu_temp()
if is_close:
if temp > 45.0:
print time.ctime(), temp, 'open air fan'
GPIO.output(channel, GPIO.HIGH)
is_close = False
else:
if temp < 38.0:
print time.ctime(), temp, 'close air fan'
GPIO.output(channel, GPIO.LOW)
is_close = True

time.sleep(2.0)
print time.ctime(), temp


if __name__ == '__main__':
main()

代码中使用了双区间,从而避免了温度变化时,风扇状态的频繁变化。之后就真的就可以整夜整夜的开着树莓派,而不用担心过热的问题了。每当树莓派CPU高速运转的时候,风扇就会转起来,其他时候,风扇就会安静下来。用手感觉一下CPU的温度。