Я пытаюсь заставить работать следующий код после борьбы с ошибкой smbus2. Теперь я обнаружил, что у меня есть следующая ошибка, и я не могу найти, как ее исправить.
Я знаю, что датчик работает, потому чтоесли я запускаю bme280.py из http://www.raspberrypi -spy.co.uk / , который работает нормально.
Итак, моя ошибка:
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)