在与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)发布于 2018-12-10 00:10:51
在这里发现了我的问题,以防其他新手也有同样的问题!
我在同一个文件夹中有一个名为bme280.py的文件,所以它加载的是该文件,而不是正确的bme280库。
解决方法很简单,就是重命名该文件。
https://stackoverflow.com/questions/53686612
复制相似问题