Created
November 7, 2021 14:14
-
-
Save HydrangeaPurple/2f5d1e5fc6352e69679c0576cdd772fd to your computer and use it in GitHub Desktop.
树莓派调温风扇脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/python3 | |
# encoding: utf-8 | |
import RPi.GPIO | |
import time | |
RPi.GPIO.setwarnings(False) | |
RPi.GPIO.setmode(RPi.GPIO.BCM) | |
RPi.GPIO.setup(14, RPi.GPIO.OUT) | |
# 被动散热, 只有超过46.5°, 才开始转, 一上来就是满速, 然后随着温度降低, 转速降低, 直到降低温度到38.5°后, 停止风扇 | |
hot = False | |
try: | |
while True: | |
tmpFile = open('/sys/class/thermal/thermal_zone0/temp') | |
temp = int(tmpFile.read()) | |
tmpFile.close() | |
if temp < 38500: | |
hot = False | |
if temp >= 46500: | |
hot = True | |
if hot: | |
time.sleep(0.2) | |
RPi.GPIO.output(14, RPi.GPIO.HIGH) | |
if not hot: | |
time.sleep(0.2) | |
RPi.GPIO.output(14, RPi.GPIO.LOW) | |
time.sleep(5) | |
except KeyboardInterrupt: | |
pass | |
time.sleep(1) | |
RPi.GPIO.output(14, RPi.GPIO.LOW) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment