Adr*_*ian 6 python-3.x raspberry-pi3
我试图在与 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 --
Run Code Online (Sandbox Code Playgroud)
代码不起作用:来自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)
Run Code Online (Sandbox Code Playgroud)
发现我的问题,将其发布在这里,以防其他新手遇到同样的问题!
我在同一文件夹中有一个名为 bme280.py 的文件,因此它正在加载该文件而不是正确的 bme280 库。
解决方案很简单,就是重命名该文件。
| 归档时间: |
|
| 查看次数: |
3851 次 |
| 最近记录: |