This is irdistance 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
安装方法
- 在HaaS Python官网下载开发板对应的固件,并完成固件烧录
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-irdistance")
import haas-python-irdistance
红外避障传感器
一、产品简介
红外避障传感器具有一对红外线发射与接收管,发射管发射出一定频率的红外线,当检测方向遇到障碍物(反射面)时,红外线反射回来被接收管接收。它常用于安装在小车上,判断前方是否有障碍物。可通过电位器设置阀值。正前方有障碍时绿灯亮起,OUT引脚为低电平,反之为高电平。红外避障传感器可以广泛应用于机器人避障、避障小车、流水线计数及黑白线循迹等众多场合。
引脚定义
- VCC:3.3V
- GND:地
- OUT:输出信号
二、技术参数
- 工作电压:3.3V-5V
- 有效检测距离:2cm-30cm
- 工作电流:10mA
- 输出电平:TTL
- 检测角度:35°
- 工作温度:-20°C~85°C
- 检测距离:可调节电位器
- 电路板尺寸:3.2cm*1.4cm
三、软件接口
红外避障传感器HaaS Python驱动:下载地址
IRDISTANCE(gpioObj) - 创建红外避障传感器对象
- 函数原型
irObj = IRDISTANCE(gpioObj)
- 参数说明
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
gpioObj | GPIO | 是 | 调用此函数前需确保gpioObj对象已经处于open状态 |
- 返回值
IRDISTANCE对象成功,返回IRDISTANCE对象;IRDISTANCE对象创建失败,抛出Exception
- 示例代码
import irdistance
from driver import GPIO
print("Testing IR detector ...")
gpioDev = GPIO()
gpioDev.open("ir")
irDev = irdistance.IRDISTANCE(gpioDev)
- 输出
Testing IR detector ...
objectDetection() - 检查红外避障传感器的状态
- 函数功能:
检查红外避障传感器的状态
- 函数原型:
IRDISTANCE.objectDetection()
- 参数说明:
无
- 返回值:
成功返回IRDISTANCE热体红外状态,0 - 有障碍物 1 - 无障碍物;失败抛出Exception
- 示例:
import irdistance
from driver import GPIO
import utime
print("Testing IR detector ...")
gpioDev = GPIO()
gpioDev.open("ir")
irDev = irdistance.IRDISTANCE(gpioDev)
while True: # 无限循环
status = irDev.objectDetection()
if status == 0:
print("object detected")
elif status == 1:
print('no object detected')
utime.sleep(1) # 打印完之后休眠1秒
- 输出
Testing IR detector ...
object detected
object detected
object detected
no object detected
no object detected
no object detected
object detected
object detected
no object detected
四、接口案例
此使用实例在board.json中定义了名为IRDISTANCE的GPIO类型的对象。在Python脚本中获取红外避障传感器的状态值并打印在日志中。
- 案例代码
{
"name": "board-name",
"version": "1.0.0",
"io": {
"ir": {
"type": "GPIO",
"port": 2,
"dir": "input",
"pull": "pullup"
}
}
}
import irdistance
from driver import GPIO
import utime
print("Testing IR detector ...")
gpioDev = GPIO()
gpioDev.open("ir")
irDev = irdistance.IRDISTANCE(gpioDev)
while True: # 无限循环
status = irDev.objectDetection()
if status == 0:
print("object detected")
elif status == 1:
print('no object detected')
utime.sleep(1) # 打印完之后休眠1秒
- 输出
Testing IR detector ...
object detected
object detected
object detected
no object detected
no object detected
no object detected
object detected
object detected
no object detected
五、工作原理
1、原理介绍
红外线接收管是将红外线光信号变成电信号的半导体器件,它的核心部件是一个特殊材料的PN结,和普通二极管相比,在结构上采取了大的改变,红外线接收管为了更多更大面积的接受入射光线,PN结面积尽量做的比较大,电极面积尽量减小,而且PN结的结深很浅,一般小于1微米。红外线接收二极管是在反向电压作用之下工作的。没有光照时,反向电流很小(一般小于0.1微安),称为暗电流。当有红外线光照时,携带能量的红外线光子进入PN结后,把能量传给共价键上的束缚电子,使部分电子挣脱共价键,从而产生电子—空穴对(简称:光生载流子)。它们在反向电压作用下参加漂移运动,使反向电流明显变大,光的强度越大,反向电流也越大。这种特性称为“光电导”。红外线接收二极管在一般照度的光线照射下,所产生的电流叫光电流。如果在外电路上接上负载,负载上就获得了电信号,而且这个电信号随着光的变化而相应变化。
参考文献及购买链接
[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
File details
Details for the file haas-python-irdistance-0.0.6.tar.gz
.
File metadata
- Download URL: haas-python-irdistance-0.0.6.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a291f50065e0f8cf86f4f74ff3d89d8a35c0c226d1fa7e32d21160bfa5cf558 |
|
MD5 | 330de542c7d40c6e2e13fe7003bcea89 |
|
BLAKE2b-256 | 25647aac9a214eba99686a5149d69e4196a7d47472958272604d24a917566fca |