Skip to main content

This is irremote 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-irremote")
import haas-python-irremote

红外接收传感器

一、产品简介

   一般家庭环境里面会有很多的遥控器,比如空调、电视机、机顶盒等等,这些都是通过红外遥控器发出的信号控制,红外遥控器发出的就是一连串的二进制脉冲码。红外接收传感器可以将这一连串的二进制脉冲码接收过来传递给MCU解析控制对应的设备。

引脚定义

  • -:地
  • S:输出信号
  • +:DC-3.3V

二、技术参数

  • 工作电压:2.7-5.5V
  • 低功耗:宽角度及长距离接收
  • 输入频率:38Khz
  • 存储温度:-40°C-125°C
  • 抗干扰:抗干扰能力强
  • 输出电平:TTL

三、软件接口

红外接收传感器HaaS Python驱动:下载地址

IRREMOTE(gpioObj) - 创建红外接收对象


  • 函数原型

irrecvObj = IRREMOTE(gpioObj)

  • 参数说明
参数 类型 必选参数? 说明
gpioObj GPIO 调用此函数前需确保gpioObj对象已经处于open状态
  • 返回值

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

  • 示例代码
import irremote
from driver import GPIO

print("Testing IRremote ...")
irrecvDev = GPIO()
irrecvDev.open("irrecv")
irrecvObj = irremote.IRREMOTE(irrecvDev)
  • 输出
Testing IRremote ...

getRemoteChar() - 获取遥控器对应的按键状态值


  • 函数功能:

获取遥控器对应的按键状态值

  • 函数原型:

IRREMOTE.getRemoteChar()

  • 参数说明:

  • 返回值:

changed,data;


其中changed为True,说明有数据值更新,False,说明没有数据值更新
data如下所示:
data返回值 类型 说明
0 string 获取遥控器按键0值
1 string 获取遥控器按键1值
2 string 获取遥控器按键2值
3 string 获取遥控器按键3值
4 string 获取遥控器按键4值
5 string 获取遥控器按键5值
6 string 获取遥控器按键6值
7 string 获取遥控器按键7值
8 string 获取遥控器按键8值
9 string 获取遥控器按键9值
PREV string 获取遥控器按键上一步
NEXT string 获取遥控器按键下一步
VOL+ string 获取遥控器按键音量增
VOL- string 获取遥控器按键音量减
START/STOP string 获取遥控器按键启动或暂停
100+ string 获取遥控器按键 step100增量值
200+ string 获取遥控器按键 step200增量值
  • 示例:
import irremote
from driver import GPIO
import utime

print("Testing IRremote ...")
irrecvDev = GPIO()
irrecvDev.open("irrecv")
irrecvObj = irremote.IRREMOTE(irrecvDev)
while True:             # 无限循环
    changed, data = irrecvObj.getRemoteChar()
    if changed == True and data != None:
        print('char %s'%data)
    utime.sleep(0.2)      # 打印完之后休眠1秒
  • 输出
Testing IRremote ...
char VOL-
char VOL+

四、接口案例

此使用实例在board.json中定义了名为IRREMOTE的GPIO类型的对象。在Python脚本中获取红外遥控器按键状态值并打印在日志中。

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

print("Testing IRremote ...")
irrecvDev = GPIO()
irrecvDev.open("irrecv")
irrecvObj = irremote.IRREMOTE(irrecvDev)
while True:             # 无限循环
    changed, data = irrecvObj.getRemoteChar()
    if changed == True and data != None:
        print('char %s'%data)
    utime.sleep(0.2)      # 打印完之后休眠1秒
  • 输出
Testing IRremote ...
char VOL-
char VOL+

五、工作原理

1、红外收发概述


   红外遥控器发出的信号是一连串的二进制脉冲码。
   为了使其在无线传输过程中免受其他红外信号的干扰,通常都是先将其调制在特定的载波频率上, 然后再经红外发射二极管发射出去,而红外线接收装置则要滤除其他杂波,只接收该特定频率的信号并将其还原成二进制脉冲码,也就是解调,接收头的信号输出脚输入到MCU进行解码控制的过程。

光电参数(T=35°C,Vcc=5V,f=38Khz)

测试波形

参考文献及购买链接

[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-irremote-0.0.7.tar.gz (9.0 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