Skip to content

Instantly share code, notes, and snippets.

@rxseger rxseger/tachfan.py
Created Oct 9, 2016

Embed
What would you like to do?
read RPM from a PC fan tachometer wired to GPIO
#!/usr/bin/python -u
# tachfan.py - read RPM from a PC fan tachometer wired to GPIO
#
# references:
# http://electronics.stackexchange.com/questions/8295/how-to-interpret-the-output-of-a-3-pin-computer-fan-speed-sensor
# http://www.formfactors.org/developer/specs/REV1_2_Public.pdf
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
TACH = 36 # BCM 16
GPIO.setwarnings(False)
GPIO.setup(TACH, GPIO.IN, pull_up_down=GPIO.PUD_UP)
t = time.time()
def fell(n):
global t
dt = time.time() - t
if dt < 0.01: return # reject spuriously short pulses
freq = 1 / dt
rpm = (freq / 2) * 60
print "%.f" % (rpm,)
t = time.time()
GPIO.add_event_detect(TACH, GPIO.FALLING, fell)
while True: time.sleep(1e9)
@bu2chlc

This comment has been minimized.

Copy link

commented Aug 4, 2019

is there any way to just get the speed one time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.