I have two similar BMP280 sensors. First, I connected one of them to GPIO 16, 17 (SDA, SCL) as well as 3V3 and GND. I ran the following script in MicroPython to read temperature and other measurements:
from machine import Pin, I2C
import bme280
# initialise i2c
i2c0 = I2C(0, sda = Pin(16), scl = Pin(17), freq = 400000)
# scan for i2c devices
print(i2c0.scan(), " (decimal)")
print(hex(i2c0.scan()[0]), " (hex)")
from time import sleep, localtime
while True:
bme0 = bme280.BME280(i2c = i2c0, mode = 2)
print(localtime())
print(bme0.values)
sleep(10)
Subsequently, I added the second sensor to GPIO 18, 19 (SDA, SCL) as well as 3V3 and GND. I extended the MicroPython script to the following:
from machine import Pin, I2C
import bme280
# initialise i2c
i2c0 = I2C(0, sda = Pin(16), scl = Pin(17), freq = 400000)
i2c1 = I2C(1, sda = Pin(18), scl = Pin(19), freq = 400000)
# scan for i2c devices
print(i2c0.scan(), " (decimal)")
print(hex(i2c0.scan()[0]), " (hex)")
print(i2c1.scan(), " (decimal)")
print(hex(i2c1.scan()[0]), " (hex)")
from time import sleep, localtime
while True:
bme0 = bme280.BME280(i2c = i2c0, mode = 2)
bme1 = bme280.BME280(i2c = i2c1, mode = 2)
print(localtime())
print(bme0.values)
print(bme1.values)
sleep(10)
However, reading the first sensor now gives the following Error:
>>> bme0 = bme280.BME280(i2c = i2c0, mode = 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/bme280.py", line 75, in __init__
OSError: [Errno 5] EIO
The problem remains when I remove the second sensor and run only the original script.
I2C scan still can find the sensor address on I2C 0:
>>> print(hex(i2c0.scan()[0]), " (hex)")
0x76 (hex)
I also swapped the sensors to see whether one of them was damaged, but the issue remained unchanged. Only the sensor on I2C 1 returns values.
What could have gone wrong here?