文档
BMP280 - 气压传感器
BMP280是一款由博世公司(Bosch)推出的高精度、低功耗的数字气压传感器模块,广泛应用于移动设备、无人机、智能家居、气象监测等领域。
数据手册
一.初始化

from machine import Pin
import bmp280
bmp= bmp280.BMP280(scl = Pin(0),sda = Pin(1))
- 参数
scl:I2C时钟线(SCL)引脚sda:I2C数据线(SDA)引脚
二.获取气压和温度

获取气压值

bmp.getPress()- 返回值
- 返回获取到的气压数值,单位:Pa
使用示例

from machine import Pin
import bmp280
from board import *
import time
#BMP280读取气压和温度
bmp= bmp280.BMP280(scl = Pin(0),sda = Pin(1))
while True:
try:
oled.fill(0)
oled.DispChar(str((str('气压:') + str(bmp.getPress()))), 0, 0, 1)
oled.show()
except:
pass
print(str('气压:') + str(bmp.getPress()))
time.sleep(1)
获取温度

bmp.getTemp()- 返回值
- 返回获取到的温度数值,单位:°C
使用示例

from machine import Pin
import bmp280
from board import *
import time
bmp= bmp280.BMP280(scl = Pin(0),sda = Pin(1))
while True:
try:
oled.fill(0)
oled.DispChar(str((str('温度:') + str(bmp.getTemp()))), 0, 0, 1)
oled.show()
except:
pass
print(str('温度:') + str(bmp.getTemp()))
time.sleep(1)
这篇文档对你有帮助吗?
去论坛提问 →