簡體   English   中英

RPI3B BME280 AttributeError:“模塊”對象沒有屬性“ load_calibration_params”

[英]RPI3B BME280 AttributeError: 'module' object has no attribute 'load_calibration_params'

我試圖與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)

發現我的問題在這里發布,以防其他新手遇到同樣的問題!

我在同一文件夾中有一個名為bme280.py的文件,因此它正在加載該文件,而不是正確的bme280庫。

解決方案就是簡單地重命名該文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM