I have the following code which is not working and giving me an error message. I'm not quite sure, but in the error message it says i2c adress 77. But the i2c-detect shows 76. The number 48 is a ADC on the same bus, which is working properly.
Does anybody have an idea what could cause the problem? I thin it could be, that the default i2c address is 77. the one of my device is 76. Is it possible to change it in the adafruit lib somehow?
Code:
import board
import busio
import adafruit_bme280
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
# OR create library object using our Bus SPI port
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bme_cs = digitalio.DigitalInOut(board.D10)
# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
while True:
print("\nTemperature: %0.1f C" % bme280.temperature)
print("Humidity: %0.1f %%" % bme280.humidity)
print("Pressure: %0.1f hPa" % bme280.pressure)
print("Altitude = %0.2f meters" % bme280.altitude)
time.sleep(2)
Error:
$ python3 i2ctest.py
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device
self.i2c.writeto(self.device_address, b"")
File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 101, in writeto
return self._i2c.writeto(address, buffer, stop=stop)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 46, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 190, in __probe_for_device
self.i2c.readfrom_into(self.device_address, result)
File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 89, in readfrom_into
return self._i2c.readfrom_into(address, buffer, stop=stop)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 53, in readfrom_into
readin = self._i2c_bus.read_bytes(address, end - start)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 179, in read_bytes
return self._device.read(number)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "i2ctest.py", line 9, in <module>
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bme280.py", line 482, in __init__
self._i2c = i2c_device.I2CDevice(i2c, address)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 69, in __init__
self.__probe_for_device()
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 192, in __probe_for_device
raise ValueError("No I2C device at address: %x" % self.device_address)
ValueError: No I2C device at address: 77
I2C-Detect:
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
Add your specific I2C address, as described in the documentation:
class adafruit_bme280.Adafruit_BME280_I2C(i2c, address=<sphinx.ext.autodoc.importer._MockObject object>)
it should look like:
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
I found it out by myself.
The problem really was the address. The default address in the lib is 0x77. My Sensor Board had 0x76.
But if you inspect very carefully, you can see three solderpads. The left and middle one are connected by a route. If you cut this route (with a needle or something) and connect the middle and right one, the address changes to 0x77 and the library is working fine:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.