Skip to content

Instantly share code, notes, and snippets.

@aallan
Last active November 5, 2020 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aallan/a5c577c14152b95e280b950d4c8a6764 to your computer and use it in GitHub Desktop.
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
#!/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()
@lasitha-sparrow
Copy link

Traceback (most recent call last):
File "cooling.py", line 6, in
import vcgencmd as vc
ImportError: No module named vcgencmd

@erickmezaR
Copy link

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