本站改版新增arduino频道
测量BMP280温度、气压和计算海拔值
#导入相关模块
import bmp280
from machine import Pin,SoftI2C,Timer
#初始化BMP280,I2C连接
i2c2 = SoftI2C(sda=Pin(7), scl=Pin(6))
BMP = bmp280.BMP280(i2c2)
#中断回调函数
def fun(tim):
    print('Air Pressure:')
    # 温度显示
    print(str(BMP.getTemp()) + ' C')
    # 湿度显示
    print(str(BMP.getPress()) + ' Pa')
    # 海拔显示
    print(str(BMP.getAltitude()) + ' m')
#开启定时器,周期1s
tim = Timer(0)
tim.init(period=1000, mode=Timer.PERIODIC, callback=fun)
Copyright © 2014 ESP56.com All Rights Reserved  
晋ICP备14006235号-22 晋公网安备14108102001165号    
执行时间: 0.0093672275543213 seconds