学物联网,来万物简单IoT物联网!!
一、产品简介
马达测速传感器与电机,码盘组成测速模块,有遮挡,输出高电平;无遮挡,输出低电平,有了高低电平,然后通过脉冲个数来确定电机的转数。马达测速传感器广泛用于电机转速检测,脉冲计数,位置限位。
引脚定义
- VCC:3.3V
- GND:地
- OUT:输出信号,有遮挡,输出高电平;无遮挡,输出低电平
二、技术参数
- 工作电压:3.3V-5V
- 驱动能力:驱动能力强,超过 15mA
- 输出形式:数字开关量输出(0和1)
- 工作温度:-20°C~85°C
- 比较器:宽电压LM393
- 电路板尺寸:2.3cm*2cm
三、软件接口
MOTORSPEED(gpioObj) - 创建马达测速传感器对象
- 函数原型
motorspeedObj = MOTORSPEED(gpioObj)
- 参数说明
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
gpioObj | GPIO | 是 | 传入GPIO对象 |
- 返回值
MOTORSPEED对象成功,返回MOTORSPEED对象;MOTORSPEED对象创建失败,抛出Exception
- 示例代码
from machine import Pin
import motorspeed
speed_cnts = 0
def speedHandler():
global speed_cnts
speed_cnts += 1
print('cnts: %d'%speed_cnts)
gpioobj = Pin(2, Pin.IN, Pin.PULL_UP)
gpioobj.irq(trig = Pin.IRQ_RISING, handle = speedHandler)
motorspeedDev = motorspeed.MOTORSPEED(gpioobj)
print("Testing motorspeed detector ...")
- 输出
Testing motorspeed detector ...
cnts: 0
cnts: 1
cnts: 2
cnts: 3
cnts: 4
objectDetection() - 检查马达测速传感器的状态
- 函数功能:
检查马达测速传感器的状态
- 函数原型:
MOTORSPEED.objectDetection()
- 参数说明:
无
- 返回值:
成功返回MOTORSPEED检测状态,0 - 无障碍物 1 - 有障碍物;失败抛出Exception
- 示例:
from machine import Pin
import motorspeed
speed_cnts = 0
def speedHandler():
global speed_cnts
speed_cnts += 1
print('cnts: %d'%speed_cnts)
gpioobj = Pin(2, Pin.IN, Pin.PULL_UP)
gpioobj.irq(trig = Pin.IRQ_RISING, handle = speedHandler)
motorspeedDev = motorspeed.MOTORSPEED(gpioobj)
print("Testing motorspeed detector ...")
print(motorspeedDev.objectDetection())
- 输出
Testing motorspeed detector ...
0
四、接口案例
- 案例代码
from machine import Pin
import motorspeed
import utime
speed_cnts = 0
def speedHandler():
global speed_cnts
speed_cnts += 1
print('cnts: %d'%speed_cnts)
gpioobj = Pin(2, Pin.IN, Pin.PULL_UP)
gpioobj.irq(trig = Pin.IRQ_RISING, handle = speedHandler)
motorspeedDev = motorspeed.MOTORSPEED(gpioobj)
print("Testing motorspeed detector ...")
while True:
print(motorspeedDev.objectDetection())
utime.sleep(1)
- 输出
Testing motorspeed detector ...
0
0
0
1
cnts: 1
0
cnts: 2
cnts: 3
cnts: 4
cnts: 5
0
参考文献及购买链接
[1] 购买链接