BME280 from Weather HAT

Hi! I’ve had Python programs running pulling data from my WeatherHAT very nicely for a few weeks now.

I’ve just added an external BME280 connected to the i2c extension on the board. Ever since then I am getting an error when running the (previously working) programs:


Traceback (most recent call last):
File “/home/pi/weatherhat-python/examples/adafruit-io_MPH.py”, line 2, in
import weatherhat
File “/usr/local/lib/python3.9/dist-packages/weatherhat/init.py”, line 7, in
from bme280 import BME280
ImportError: cannot import name ‘BME280’ from ‘bme280’ (/home/pi/weatherhat-python/examples/bme280.py)

I’ve done some Googling, and tried downgrading the bme280 library using:

sudo pip install pimoroni-bme280==0.0.2

This hasn’t made any difference. I’m pretty stuck at the moment, can anyone help a Python newbie?

Thanks!

Nigel

You have to cut the address select jumper on the back of the bme280, you added to i2c. You can’t have two devices with the same i2c address. You will also have to adjust your code to use two bme280’s.

Ahah! Thanks very much for the info. I’ll look into what’s needed.

This is code I used on a build I have that has two BME280’s wired up to i2c.

from bme280 import BME280

try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus

bus = SMBus(1)
bme_in = BME280(0x76)   #default address, jumper not cut 
bme_out = BME280(0x77)  #alternate address, jumper cut

Then to read them it goes something like this.

temperature_in = bme_in.get_temperature()
temperature_out = bme_out.get_temperature()
humidity_in = bme_in.get_humidity()
humidity_out = bme_out.get_humidity()

etc.

EDIT: For me I just run the stock BME280 installer. They will both use the one library.
sudo pip install pimoroni-bme280 smbus
For you the weather hat installer should be enough to run both BME280’s

1 Like

That’s great! Thanks so much. I’m trying to figure out how to change the address on the particular version I have. In the meantime, my original problem still happens with the “other” BME280 completely disconnected, which is very strange. I think I’m going to try a clean install on the pi to see if that gets me back to where I was.

Nigel

Well, I cloned the install from github again, and now it works so I’m starting from a good place again. Thanks for the steer on i2c addressing, that’s next on the list.

Nigel

It works! Yay! I found that some cheap BME280s I bought on line just would not change address, it
wasn’t possible to sever the link between the first two solder pads. I ponied up for a better one, and
that works a treat. I think the documentation on the Weather Hat could be better, I was initially trying to make sense of, and connect to, the obvious connection on the front of the board. It was only later that I found the actual i2c connector on the side of the board. Anyway, got there in the end, so thanks for your help.

Glad you got it working! I’ve tidied up the bit of the shop page description that refers to where the ADC and I2C headers are located on Weather HAT to try and make it a bit clearer which is which.

1 Like