物联网AI MicroPython传感器学习 之 马达测速传感器

学物联网,来万物简单IoT物联网!!在这里插入图片描述

一、产品简介

马达测速传感器与电机,码盘组成测速模块,有遮挡,输出高电平;无遮挡,输出低电平,有了高低电平,然后通过脉冲个数来确定电机的转数。马达测速传感器广泛用于电机转速检测,脉冲计数,位置限位。
image.png
引脚定义

  • VCC:3.3V
  • GND:地
  • OUT:输出信号,有遮挡,输出高电平;无遮挡,输出低电平

二、技术参数

  • 工作电压:3.3V-5V
  • 驱动能力:驱动能力强,超过 15mA
  • 输出形式:数字开关量输出(0和1)
  • 工作温度:-20°C~85°C
  • 比较器:宽电压LM393
  • 电路板尺寸:2.3cm*2cm

三、软件接口

MOTORSPEED(gpioObj) - 创建马达测速传感器对象

  • 函数原型

motorspeedObj = MOTORSPEED(gpioObj)

  • 参数说明
参数类型必选参数?说明
gpioObjGPIO传入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] 购买链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值