Package: haas-python-irremote
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, seeHaaS Python official website,Creative Case,Hardware Building Blocks安装方法在HaaS Python官网下载开发板对应的固件，并完成固件烧录Download the firmware corresponding to the development board atHaaS Python websiteand 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 ongithub, Our engineers will answer in timeimport 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)参数说明参数类型必选参数？说明gpioObjGPIO是调用此函数前需确保gpioObj对象已经处于open状态返回值IRREMOTE对象成功，返回IRREMOTE对象；IRREMOTE对象创建失败，抛出Exception示例代码importirremotefromdriverimportGPIOprint("Testing IRremote ...")irrecvDev=GPIO()irrecvDev.open("irrecv")irrecvObj=irremote.IRREMOTE(irrecvDev)输出TestingIRremote...getRemoteChar() - 获取遥控器对应的按键状态值函数功能：获取遥控器对应的按键状态值函数原型：IRREMOTE.getRemoteChar()参数说明：无返回值：changed，data；其中changed为True，说明有数据值更新，False，说明没有数据值更新data如下所示：data返回值类型说明0string获取遥控器按键0值1string获取遥控器按键1值2string获取遥控器按键2值3string获取遥控器按键3值4string获取遥控器按键4值5string获取遥控器按键5值6string获取遥控器按键6值7string获取遥控器按键7值8string获取遥控器按键8值9string获取遥控器按键9值PREVstring获取遥控器按键上一步NEXTstring获取遥控器按键下一步VOL+string获取遥控器按键音量增VOL-string获取遥控器按键音量减START/STOPstring获取遥控器按键启动或暂停100+string获取遥控器按键 step100增量值200+string获取遥控器按键 step200增量值示例：importirremotefromdriverimportGPIOimportutimeprint("Testing IRremote ...")irrecvDev=GPIO()irrecvDev.open("irrecv")irrecvObj=irremote.IRREMOTE(irrecvDev)whileTrue:# 无限循环changed,data=irrecvObj.getRemoteChar()ifchanged==Trueanddata!=None:print('char%s'%data)utime.sleep(0.2)# 打印完之后休眠1秒输出TestingIRremote...charVOL-charVOL+四、接口案例此使用实例在board.json中定义了名为IRREMOTE的GPIO类型的对象。在Python脚本中获取红外遥控器按键状态值并打印在日志中。案例代码{"name":"board-name","version":"1.0.0","io":{"irrecv":{"type":"GPIO","port":34,"dir":"irq","pull":"pullup","intMode":"both"}}}importirremotefromdriverimportGPIOimportutimeprint("Testing IRremote ...")irrecvDev=GPIO()irrecvDev.open("irrecv")irrecvObj=irremote.IRREMOTE(irrecvDev)whileTrue:# 无限循环changed,data=irrecvObj.getRemoteChar()ifchanged==Trueanddata!=None:print('char%s'%data)utime.sleep(0.2)# 打印完之后休眠1秒输出TestingIRremote...charVOL-charVOL+五、工作原理1、红外收发概述红外遥控器发出的信号是一连串的二进制脉冲码。为了使其在无线传输过程中免受其他红外信号的干扰,通常都是先将其调制在特定的载波频率上, 然后再经红外发射二极管发射出去,而红外线接收装置则要滤除其他杂波,只接收该特定频率的信号并将其还原成二进制脉冲码,也就是解调，接收头的信号输出脚输入到MCU进行解码控制的过程。光电参数（T=35°C,Vcc=5V,f=38Khz）测试波形参考文献及购买链接[1]红外接收传感器