I'm trying to setup a Raspberry Pi 3 B+ with a Waveshare BME280 Environmental Sensor. I followed this guide to wire the cables and ran the supplied bme280.py script. My sensor has 2 additional cables, the CS and ADDR/MISO, that are not present in the model on the guide but the rest are plugged in to the same GPIO pins. The I2C and SPI interfaces are enabled and I am running the latest Raspbian OS Lite.
When I run the script, I get the following message:
Traceback (most recent call last):
File "bme280.py", line 172, in <module>
main()
File "bme280.py", line 161, in main
(chip_id, chip_version) = readBME280ID()
File "bme280.py", line 56, in readBME280ID
(chip_id, chip_version) = bus.read_i2c_block_data(addr, REG_ID, 2)
OSError: [Errno 121] Remote I/O error
There's another odd issue: when I run i2cdetect -y 1
I get every line with dashes, but if I run it a second time immediately after, I get x77 to show up, but x76 still doesn't.
I found a similar thread and tried modifying my /boot/config.txt file by adding i2c_baudrate=100000
and rebooting but that did not fix it.
I made sure to test the pi using gpiotest and the results came back as
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Failed user gpios: None
I had gotten similar issues using a DHT11 sensor and running Adafruit libraries and got an error signifying there was no data flowing from the sensor. I tried using several different sensors and Raspberry Pis and have reinstalled the OS several times over. At this point, I'm not sure how to proceed. Any help is appreciated.
I managed to create a very hacky solution to this issue. Since i2cdetect seems to only read devices on the second (or later) times it is run, I decided to simulate running it inside the sensor script.
I added the following lines to my code:
import os
from time import sleep
os.system('i2cdetect -y 1')
sleep(0.1)
os.system('i2cdetect -y 1')
The output still shows the first i2cdetect command not reading any devices so I had to add a second one. I noticed sometimes both of them read no data so I added a 1/10th second sleep command.
This gets unnecessary output from the i2cdetect commands but I ignore it and only send the temperature data to my server.