RPI3B BME280 AttributeError: 'module' object has no attribute 'load_calibration_params'
Asked Answered
B

2

6

I'm trying to get the following code working after battling with an smbus2 error i now find i have the following error and can't find how to fix it.

I know the sensor is working because if I run bme280.py from http://www.raspberrypi-spy.co.uk/ that works ok.

So my error is:

pi@wpi:~/weather $ python bme280_sensor.py
Traceback (most recent call last):
  File "bme280_sensor.py", line 9, in <module>
    bme280.load_calibration_params(bus, address)
AttributeError: 'module' object has no attribute 'load_calibration_params'


i2detect 
pi@wpi:~/weather $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --

Code not working: from https://pypi.org/project/RPi.bme280/

import smbus2
import bme280

port = 1
address = 0x76
bus = smbus2.SMBus(port)

calibration_params = bme280.load_calibration_params(bus, address)

# the sample method will take a single reading and return a
# compensated_reading object
data = bme280.sample(bus, address, calibration_params)

# the compensated_reading class has the following attributes
print(data.id)
print(data.timestamp)
print(data.temperature)
print(data.pressure)
print(data.humidity)

# there is a handy string representation too
print(data)
Beestings answered 8/12, 2018 at 20:20 Comment(0)
B
4

Found my issue posting it here in case any other newbies have the same issue!

I had a file called bme280.py in the same folder so it was loading that file instead of the correct bme280 library.

The solution was simply to rename that file.

Beestings answered 9/12, 2018 at 16:10 Comment(0)
E
3

Mine worked after I installed RPi.bme280

$ sudo pip3 install RPi.bme280

This is from the bme280 documentation: https://github.com/rm-hull/bme280

Enugu answered 27/10, 2022 at 23:47 Comment(2)
This is a the right answer for a Raspberry Pi; you need to install RPi.bme280, and not bme280.Disseise
This worked for me as well. Use pip install RPi.bme280Ernie

© 2022 - 2025 — McMap. All rights reserved.