首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块模块:“RPI3B”对象没有“”load_calibration_params“”属性“”

模块模块:“RPI3B”对象没有“”load_calibration_params“”属性“”
EN

Stack Overflow用户
提问于 2018-12-09 04:20:53
回答 1查看 2.1K关注 0票数 0

在与smbus2错误作斗争后,我正在尝试让以下代码工作,现在我发现我有以下错误,但找不到如何修复它。

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

所以我的错误是:

代码语言:javascript
复制
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/

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2018-12-10 00:10:51

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

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

解决方法很简单,就是重命名该文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53686612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档