所以我得到的是 Noctua 风扇(产品链接:https://noctua.at/en/products/fan/nf-a4x20-5v/specification) 连接到 Raspberry Pi 3。我想知道每秒风扇的转速。我有一个 Python 脚本,它为我提供了一个 RPM 值,但 RPM 似乎不准确。风扇速度在满负荷时为 5000rpm(+/-10%),而脚本给出的 RPM 值是预期值的一半。我需要帮助,如何使用 PWM(脉冲宽度调制)或任何其他技术获得准确的读数。
def calculate_elapse(channel): # callback function
global pulse, start_timer, elapse
pulse+=1 # increase pulse by 1 whenever interrupt occurred
elapse = time.time() - start_timer # elapse for every 1 complete rotation made!
start_timer = time.time() # let current time equals to start_timer
def calculate_speed(r_cm):
global pulse,elapse,rpm,dist_km,dist_meas,km_per_sec,km_per_hour
if elapse !=0: # to avoid DivisionByZero error
rpm = 1/elapse * 60
circ_cm = (2*math.pi)*r_cm # calculate wheel circumference in CM
dist_km = circ_cm/100000 # convert cm to km
km_per_sec = dist_km / elapse # calculate KM/sec
km_per_hour = km_per_sec * 3600 # calculate KM/h
dist_meas = (dist_km*pulse)*1000 # measure distance traverse in meter
return km_per_hour