Package: haas-python-fheartbeat
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-fheartbeat")
import haas-python-fheartbeat手指侦测心跳传感器一、产品简介手指侦测心跳传感器是通过LED和光电晶体管监测手指血压脉冲，来判断人的心脏跳动。其结构简单成本低廉，只能是做一些实验和学习相关的知识（没有医疗实用价值）引脚定义-: GND+: 3.3VS: 模拟信号输出二、软件接口手指侦测心跳传感器HaaS Python驱动：下载地址FHEARTBEAT(adcObj) - 创建FHEARTBEAT驱动对象函数原型:fheartbeatObj = FHEARTBEAT(adcObj)参数说明:参数类型必选参数？说明adcObjADC是调用此函数前需确保adcObj对象已经处于open状态返回值:创建对象成功，返回FHEARTBEAT对象；FHEARTBEAT对象创建失败，抛出Exception示例代码:fromfheartbeatimport*print("Testing fheartbeat  ...")adc=ADC()adc.open("fheartbeat")fheartbeatDev=FHEARTBEAT(adc)输出:Testing fheartbeat  ...getVoltage - 测量手指侦测心跳电压值函数功能:量测手指侦测心跳电压值并返回测量结果函数原型:FHEARTBEAT.getVoltage()参数说明:
无返回值:成功返回手指侦测心跳电压值测量结果（数据类型：浮点型；单位：mV）；失败抛出Exception示例:fromfheartbeatimport*print("Testing fheartbeat  ...")adc=ADC()adc.open("fheartbeat")fheartbeatDev=FHEARTBEAT(adc)voltage=fheartbeatDev.getVoltage()print("voltage:%d"%voltage)输出:Testing fheartbeat  ...
voltage: 800.0三、接口案例此使用实例在board.json中定义了名为FHEARTBEAT的ADC类型的对象。在Python脚本中周期性的获取手指侦测心跳电压值测量结果并打印在日志中。代码:#board.json配置：{"name":"board-name","version":"1.0.0","io":{"fheartbeat":{"type":"ADC","port":4,"width":2,"atten":3,"sampling":12000000}},"debugLevel":"ERROR","repl":"disable"}# Python代码importutime# 延时API所在组件fromfheartbeatimport*i=0trip={}print("Testing fheartbeat  ...")adc=ADC()adc.open("fheartbeat")fheartbeatDev=FHEARTBEAT(adc)while1:voltage=fheartbeatDev.getVoltage()trip[i]=voltagei=i+1ifi==50:i=0print("trip:",trip)utime.sleep_ms(10)输出：...
Testing fheartbeat  ...
trip: {0: 3719, 1: 3720, 2: 3719, 3: 3720, 4: 3717, 5: 3734, 6: 3726, 7: 3732, 8: 3730, 9: 3732, 10: 3724, 11: 3724, 12: 3732, 13: 3732, 14: 3734, 15: 3730, 16: 3726, 17: 3719, 18: 3734, 19: 3728, 20: 3724, 21: 3728, 22: 3732, 23: 3720, 24: 3732, 25: 3724, 26: 3720, 27: 3720, 28: 3724, 29: 3719, 30: 3717, 31: 3726, 32: 3720, 33: 3722, 34: 3719, 35: 3734, 36: 3722, 37: 3717, 38: 3722, 39: 3720, 40: 3719, 41: 3720, 42: 3711, 43: 3717, 44: 3734, 45: 3724, 46: 3722, 47: 3720, 48: 3724, 49: 3717}
trip: {0: 3732, 1: 3720, 2: 3720, 3: 3713, 4: 3719, 5: 3719, 6: 3717, 7: 3720, 8: 3717, 9: 3717, 10: 3719, 11: 3717, 12: 3724, 13: 3724, 14: 3720, 15: 3720, 16: 3720, 17: 3724, 18: 3713, 19: 3719, 20: 3719, 21: 3715, 22: 3713, 23: 3713, 24: 3720, 25: 3717, 26: 3713, 27: 3717, 28: 3720, 29: 3709, 30: 3722, 31: 3715, 32: 3719, 33: 3719, 34: 3715, 35: 3709, 36: 3724, 37: 3719, 38: 3717, 39: 3717, 40: 3719, 41: 3711, 42: 3728, 43: 3720, 44: 3719, 45: 3724, 46: 3717, 47: 3717, 48: 3717, 49: 3732}
...四、通信协议主控芯片通过ADC读取手指侦测心跳传感器的电压值数据。五、工作原理当手指放在发射器与接收器之间，红外发射LED发射的光将穿过手指，到被接收器接收。而血压会随着脉搏变化，导致红外接收器接收到的光通量也会随之变化，因此可以通过红外光接收的情况来统计监测心跳。其大概的电原理示意图如下：参考文献及购买链接[1]商品链接