风速计与覆盆子pi

时间:2013-12-03 13:08:07

标签: python raspberry-pi

我真正需要帮助的是一种通过使用Python的风速计来计算风速的方法。到目前为止,我唯一的问题是测量一秒钟发生的“点击次数”。风速计的一次旋转导致开关打开和关闭2次。

我希望代码执行的示例如下:

每秒10次点击=每小时5英里风

对于我每秒如何测量脉冲,我们非常感激。

问候。

到目前为止

代码(如果按下开关,它会连续打印输出并记录):

#!/usr/bin/env python
import uadi2c
import mcp23017

addr2 = 0x21
dio = uadi2c.uadi2c(addr2, debug=False)
portA = mcp23017.GPIOA
portB = mcp23017.GPIOB
dirA = mcp23017.IODIRA
dirB = mcp23017.IODIRB
# chip 1, all output, chip 2 A input, B output
dio.write8(dirA, 0)
dio.write8(dirB, 0x40)


# Now loop reading PA and writing to PB and the terminal

while True:
    stuff = dio.readU8(portB)
    dio.write8(portA, stuff)
    print 'Data read from port B: {0:=08b}'.format(stuff)

0 个答案:

没有答案