Issue
I'm trying to create a sensing station using the BME280 temperature, pressure, and humidity sensor and a raspberry pi. When I run my python code, I receive the error: "RuntimeError: Unable to find bme280 on 0x76, IOError" When I run i2cdetect -y 1, the address the device is on is 0x77. How do I fix this? I'm very new to electronics work, so any and all help is appreciated. My code is below.
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
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
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)
Solution
There are two possible solutions to fix this problem.
- The BME-280 has an SDO line which sets the devices address - 0x76 if connected to Gnd, 0x77 if connected to Vdd. You probably have it connected to Vdd, so you can connect it to Gnd instead.
- While initializing the BME object you can pass it a parameter to determine its address -
i2c_addr
. The default value isI2C_ADDRESS_GND
but you can change it:bme280 = BME280(i2c_dev=bus, i2c_addr=I2C_ADDRESS_VCC)
References: BME datasheet, pimoroni module
Answered By - TDG Answer Checked By - Mary Flores (WPSolving Volunteer)