首页 文章

RPI3B BME280 AttributeError:'module'对象没有属性'load_calibration_params'

提问于
浏览
0

我试图让以下代码在与smbus2错误作斗争后工作我现在发现我有以下错误,但无法找到解决方法 .

我知道传感器正在工作,因为如果我从http://www.raspberrypi-spy.co.uk/运行bme280.py就行了 .

所以我的错误是:

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 --

代码无效:来自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)

1 回答

  • 0

    发现我的问题在这里发布,以防任何其他新手有同样的问题!

    我在同一文件夹中有一个名为bme280.py的文件,因此它正在加载该文件而不是正确的bme280库 .

    解决方案只是重命名该文件 .

相关问题