1

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?

7
  • 1
    you could connect both sensors to the same bus
    – jsotola
    Sep 6, 2022 at 16:41
  • 1
    Why are you using so strange pins? The default for I2C0 are GPIO pins 0 and 1 and for I2C1 GPIO 2 and 3. I'm not sure what happens when you use arbitrary pins, but it may lead to software emulation instead of hardware.
    – PMF
    Sep 6, 2022 at 16:46
  • @jsotola Can I, despite the sensors having the same standard address? It was convenient to use different pins with the jumper wires I have. Sep 6, 2022 at 17:19
  • @PMF It actually worked after changing the pins. I thought it should work regardless of which pins you use... Sep 6, 2022 at 17:20
  • the datasheet states that the device address is jumper selectable ... that allows two devices to be connected to one bus without any external select circuitry
    – jsotola
    Sep 6, 2022 at 17:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.