Package: haas-python-bmp280
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-bmp280")
import haas-python-bmp280气压传感器 - BMP280一、产品简介BMP280是博世出品的气压传感器，它集成了压电压力传感单元、信号处理电路及模数转换器,气压值可以通过SPI或I2C读出,在室内导航、无人机、气象站等场景有广泛应用。引脚定义VCC: 3.3VGND: GNDSCL: IIC时钟SDA: IIC数据CSB: 3.3VSDO: GND二、技术参数供电电压:1.9~3.6V可以采用I2C或SPI通信协议（HaaS Python实现了IIC接口驱动），I2C最高传输速率可到3.4MHz，SPI最高传输速率可达10MHz，当CSB管脚接VCC时选择为IIC接口，当CSB管脚接GND时选择为SPI接口，I2C地址可配置0X76或者0x77,取决于SDO，SDO接GND时I2C地址维0x76，SDO接VCC时I2C地址为0x77气压测量范围： 300hPa至1100hPa，最大误差为±12hPa封装:8-pin LGA metal-lid，2.0mm * 2.5mm, height: 0.95mm工作温度范围: -40摄氏度 - +85摄氏度三、软件接口BMP280气压传感器HaaS Python驱动：下载地址BMP280(i2cObj) - 创建BMP280驱动对象函数原型：bmpObj = BMP280(i2cObj)参数说明:参数类型必选参数？说明i2cObjI2C是调用此函数前需确保i2cObj对象已经处于open状态返回值:
BMP280对象成功，返回BMP280对象；BMP280对象创建失败，抛出Exception示例代码:fromdriverimportI2C# 驱动库importbmp280# BMP280温湿度传感器驱动库# 初始化I2C类型的设备i2cObj=I2C()i2cObj.open("bmp280")# 按照board.json中名为"bmp280"的设备节点的配置参数（主设备I2C端口号，从设备地址，总线频率等）初始化I2C类型设备对象print("bmp280 inited!")baroDev=bmp280.BMP280(i2cObj)# 初始化BMP280传感器输出:bmp280 inited!getPressure - 测量气压函数功能:
量测气压值并返回测量结果函数原型:BMP280.getPressure()参数说明:
无返回值:
成功返回温度测量结果（数据类型：浮点型；单位：Pa）；失败抛出Exception示例:fromdriverimportI2C# 驱动库importbmp280# BMP280温湿度传感器驱动库# 初始化I2C类型的设备i2cObj=I2C()i2cObj.open("bmp280")# 按照board.json中名为"bmp280"的设备节点的配置参数（主设备I2C端口号，从设备地址，总线频率等）初始化I2C类型设备对象baroDev=bmp280.BMP280(i2cObj)# 初始化BMP280传感器pressure=baroDev.getPressure()print("pressure is ",pressure,"Pa")输出:pressure is 103000Pa四、接口案例此使用实例在board.json中定义了名为bmp280的I2C类型的对象。在Python脚本中周期性的获取温湿度测量结果并打印在日志中。代码:#board.json配置：{"name":"board-name","version":"1.0.0","io":{"bmp280":{"type":"I2C","port":0,"addrWidth":7,"freq":400000,"mode":"master","devAddr":118}},"debugLevel":"ERROR","repl":"disable"}# Python代码importutime# 延时API所在组件fromdriverimportI2C# 驱动库importbmp280# BMP280温湿度传感器驱动库# 初始化I2C类型的设备i2cObj=I2C()i2cObj.open("bmp280")# 按照board.json中名为"bmp280"的设备节点的配置参数（主设备I2C端口号，从设备地址，总线频率等）初始化I2C类型设备对象baroDev=bmp280.BMP280(i2cObj)# 初始化BMP280传感器# 通过温湿度传感器读取温湿度信息defget_pressure():pressure=baroDev.getPressure()# 获取大气压测量结果print("The pressure is:%.1f"%pressure)returnpressure# 返回读取到的大气压值if__name__=='__main__':whileTrue:data=get_pressure()# 读取温度信息和相对湿度信息utime.sleep(1)# 每隔1秒钟进行一次温湿度信息测量和打印i2cObj.close()# 关闭I2C设备对象输出:...
The pressure is 103000Pa
...五、通信协议主控芯片和 BMP280 传感器之间通信所用命令字如下表所示：序号命令字功能说明命令字宏定义10x88读T1校准参数CMD_READ_DIG_T120x82读T2校准参数CMD_READ_DIG_T230x8c读T3校准参数CMD_READ_DIG_T340x8e读P1校准参数CMD_READ_DIG_P150x90读P2校准参数CMD_READ_DIG_P260x92读P3校准参数CMD_READ_DIG_P370x94读P4校准参数CMD_READ_DIG_P480x96读P5校准参数CMD_READ_DIG_P590x98读P6校准参数CMD_READ_DIG_P6100x9a读P7校准参数CMD_READ_DIG_P7110x9c读P8校准参数CMD_READ_DIG_P8120xFA读取温度CMD_READ_TEMPERATURE130xF7读取大气压CMD_READ_PRESSURE实际控制此传感器的流程可参考如下描述。一次获取数据通过IIC发送CMD_READ_DIG_T1-CMD_READ_DIG_T3获取温度校准参数并且发送CMD_READ_DIG_P1-CMD_READ_DIG_P8获取气压校准参数；通过IIC发送CMD_READ_TEMPERATURE获取温度RAW数据，通过温度校准参数计算得到实际摄氏度温度；通过IIC发送CMD_READ_PRESSURE获取气压RAW数据，通过气压校准参数和温度校准参数数计算得到实际气压Pa；六、工作原理从下图可以看到bmp280内部集成了压力传感单元，通过ADC采样输入到校正储存器。通过数字接口IIC或SPI读取数据。引脚分布如下，3和4号脚是IIC总线接口的SCL和SDA管脚。典型电路如下，由于SCL和SDA为开漏输出，驱动能力不足，需要接上拉电阻。要通过IIC总线访问bmp280，CSB需要接到VDDIO。参考文献及购买链接[1]BMP280气压传感器[2]购买链接