Last active
November 5, 2020 11:29
-
-
Save aallan/a5c577c14152b95e280b950d4c8a6764 to your computer and use it in GitHub Desktop.
Toggle a cooling fan on and off to keep the Raspberry Pi between 70 and 75C
This file contains hidden or 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/env python3 | |
import sys | |
import os | |
import time | |
import vcgencmd as vc | |
from gpiozero import OutputDevice | |
def main(): | |
fan = OutputDevice(18) | |
while True: | |
temp = int(vc.measure_temp()) | |
print(temp) | |
if temp >= 75: | |
fan.on() | |
print("fan.on()") | |
elif temp <= 70: | |
fan.off() | |
print("fan.off()") | |
time.sleep(1) | |
if __name__ == '__main__': | |
main() |
you need to install
https://github.com/nicmcd/vcgencmd
test it like this
from vcgencmd import Vcgencmd
vcgm = Vcgencmd()
output = vcgm.measure_temp()
print(output)
remember to run as root if not you will nto have access to GIO in the test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Traceback (most recent call last):
File "cooling.py", line 6, in
import vcgencmd as vc
ImportError: No module named vcgencmd