Skip to main content

This is motorspeed driver for HaaS Python. HaaS Python is forked from micropython.

Project description

HaaS Python介绍

HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架,兼容MicroPython编程规范,依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力,从而解决了物联网应用开发难的问题。有了Python轻应用框架,物联网编程不再局限于专业软件开发人员,一般的技术员也可以快速实现复杂的物联网需求。 更多HaaS Python介绍和开发资料见HaaS Python官网,创意案例, 硬件积木

HaaS Python is a set of low-code programming frameworks newly developed by Alibaba Cloud IoT team. It is compatible with MicroPython programming specifications. It relies on the hardware and software building blocks of the HaaS platform to provide capabilities commonly used in IoT scenarios such as AI, payment, Bluetooth network configuration, cloud connection, and UI. Solve the difficult problem of IoT application development. With the Python light application framework, IoT programming is no longer limited to professional software developers, and general technicians can quickly implement complex IoT requirements. For more HaaS Python introduction and development materials, see HaaS Python official website, Creative Case, Hardware Building Blocks

安装方法

Download the firmware corresponding to the development board at HaaS Python website and complete the firmware burning

  • 在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题,欢迎在github上向我们提交issue,我们的工程师会及时解答

Run the following commands on the development board to complete the installation and use. If you encounter problems during use, please submit an issue to us on github, Our engineers will answer in time

import upip
upip.install("haas-python-motorspeed")
import haas-python-motorspeed

马达测速传感器

一、产品简介

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

引脚定义

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

二、技术参数

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

三、软件接口

马达测速传感器 HaaS Python驱动:下载地址

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


  • 函数原型

motorspeedObj = MOTORSPEED(gpioObj,func)

  • 参数说明
参数 类型 必选参数? 说明
gpioObj GPIO 调用此函数前需确保gpioObj对象已经处于open状态
func 回调函数 默认无回调函数,如果需要使用中断回调处理,则需要传入该参数
  • 返回值

MOTORSPEED对象成功,返回MOTORSPEED对象;MOTORSPEED对象创建失败,抛出Exception

  • 示例代码-无回调函数
import motorspeed
from driver import GPIO

print("Testing motorspeed detector ...")
gpioDev = GPIO()
gpioDev.open("motorspeed")
motorspeedDev = motorspeed.MOTORSPEED(gpioDev)
  • 输出
Testing motorspeed detector ...

  • 示例代码-有回调函数
import motorspeed
from driver import GPIO

speed_cnts = 0

def speed_handler():
    global speed_cnts
    speed_cnts += 1
    print('cnts: %d'%speed_cnts)

print("Testing motorspeed detector ...")
gpioDev = GPIO()
gpioDev.open("motorspeed")
motorspeedDev = motorspeed.MOTORSPEED(gpioDev,speed_handler)
  • 输出
Testing motorspeed detector ...
cnts: 0
cnts: 1
cnts: 2
cnts: 3
cnts: 4

objectDetection() - 检查马达测速传感器的状态


  • 函数功能:

检查马达测速传感器的状态

  • 函数原型:

MOTORSPEED.objectDetection()

  • 参数说明:

  • 返回值:

成功返回MOTORSPEED检测状态,0 - 无障碍物 1 - 有障碍物;失败抛出Exception

  • 示例:
import motorspeed
from driver import GPIO

print("Testing motorspeed detector ...")
gpioDev = GPIO()
gpioDev.open("motorspeed")
motorspeedDev = motorspeed.MOTORSPEED(gpioDev)
print(motorspeedDev.objectDetection())
  • 输出
Testing motorspeed detector ...
0

四、接口案例

此使用实例在board.json中定义了名为MOTORSPEED的GPIO类型的对象。在Python脚本中获取传感器的输出状态并打印在日志中。

  • 案例代码
{
  "name": "board-name",
  "version": "1.0.0",
  "io": {
   "motorspeed": {
        "type": "GPIO",
        "port": 2,
        "dir": "irq",
        "pull": "pullup",
        "intMode": "falling"
    }
  },
}
import motorspeed
from driver import GPIO
import utime

speed_cnts = 0
def speed_handler(data):
    global speed_cnts
    speed_cnts += 1
    print('cnts: %d'%speed_cnts)
print("Testing motorspeed detector ...")
gpioDev = GPIO()
gpioDev.open("motorspeed")
motorspeedDev = motorspeed.MOTORSPEED(gpioDev,speed_handler)
while 1:
    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] 购买链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haas-python-motorspeed-0.0.7.tar.gz (7.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page