You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改BME280传感器I2C地址?解决树莓派识别报错问题

解决BME280传感器地址不匹配的问题

你的错误原因很直接:代码中默认使用了BME280的0x76地址,但通过i2cdetect -y 1检测到的实际传感器地址是0x77,只需要在初始化传感器时指定正确的地址即可修复问题。

修改后的代码:

import time
try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus
from bme280 import BME280

print("""bmeTest.py - Read temperature, pressure, and humidity

Press Ctrl+C to exit!

""")

# Initialize the BME280,指定正确的I2C地址0x77
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus, address=0x77)

while True:
    temperature = bme280.get_temperature()
    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()
    print('{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))
    time.sleep(1)

补充说明:

BME280的I2C地址由SDO引脚的接线决定:

  • SDO接GND时,地址为0x76
  • SDO接VCC时,地址为0x77
    你的传感器当前地址是0x77,说明SDO引脚被拉高了,这是正常的硬件配置情况。

内容的提问来源于stack exchange,提问作者Max

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 07:32:03