问题
I have adafruit pressure and temperature sensor BMP180 connected to I2C of Raspberry Pi 3. The device is detected on 0x77 address of I2C, i2cdump runs with no error and shows correct values (e.g. byte 0x55 in 0xD0 as described in Bosch documentation). But reading a byte in most cases results in input/output error.
pi@raspberrypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
pi@raspberrypi:~/Adafruit_Python_BMP $ i2cdump -y 1 0x77
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
10: XX XX XX 00 00 00 00 00 00 00 00 00 00 00 00 00 XXX.............
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: a5 94 46 29 82 27 75 20 c8 0b 22 91 fb 57 c7 11 ??F)?'u ??"??W??
90: 85 ca 61 f6 45 8a 19 73 00 30 80 00 d1 f6 0a d4 ??a?E??s.0?.????
a0: a5 94 46 29 82 27 75 20 c8 0b 22 91 fb 57 c7 11 ??F)?'u ??"??W??
b0: 85 ca 61 f6 45 8a 19 73 00 30 80 00 d1 f6 0a d4 ??a?E??s.0?.????
c0: 00 00 bc 33 00 00 00 00 00 00 00 10 00 00 00 03 ..?3.......?...?
d0: 55 02 06 00 00 00 00 00 00 00 00 00 00 00 00 00 U??.............
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 80 00 00 00 00 00 00 00 00 00 ......?.........
pi@raspberrypi:~/Adafruit_Python_BMP $ i2cget -y 1 0x77 0xd0
0x55
pi@raspberrypi:~/Adafruit_Python_BMP $ i2cget -y 1 0x77 0xd0
Error: Read failed
pi@raspberrypi:~/Adafruit_Python_BMP $ i2cget -y 1 0x77 0xd0
Error: Read failed
Executing example from Adafruit (for BMP180 sensor) in most cases also returns error:
pi@raspberrypi:~/Adafruit_Python_BMP $ python test.py
Temp = 23.40 *C
Pressure = 99105.00 Pa
pi@raspberrypi:~/Adafruit_Python_BMP $ python test.py
Traceback (most recent call last):
File "test.py", line 3, in <module>
sensor = BMP085.BMP085()
File "/home/pi/Adafruit_Python_BMP/Adafruit_BMP/BMP085.py", line 69, in __init__
self._load_calibration()
File "/home/pi/Adafruit_Python_BMP/Adafruit_BMP/BMP085.py", line 72, in _load_calibration
self.cal_AC1 = self._device.readS16BE(BMP085_CAL_AC1) # INT16
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 200, in readS16BE
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 177, in readS16
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 164, in readU16
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 173, in read_word_data
IOError: [Errno 5] Input/output error
I have also written scripts to read bytes from this sensor, using either smbus2 or smbus-cffi. The result is the same: rarely bytes are read, in most cases I get errors:
➜ birdwatcher git:(master) ✗ cat bmp180.py | ssh pi@192.168.1.11 sudo python -
2016-12-30 19:30:40,608 __main__ DEBUG AC1 = -29482 [-0x732a]
2016-12-30 19:30:40,609 __main__ DEBUG AC2 = 22523 [0x57fb]
2016-12-30 19:30:40,609 __main__ DEBUG AC3 = 4551 [0x11c7]
2016-12-30 19:30:40,610 __main__ DEBUG AC4 = 51845 [0xca85]
2016-12-30 19:30:40,610 __main__ DEBUG AC5 = 63073 [0xf661]
2016-12-30 19:30:40,610 __main__ DEBUG AC6 = 35397 [0x8a45]
➜ birdwatcher git:(master) ✗ cat bmp180.py | ssh pi@192.168.1.11 sudo python -
Traceback (most recent call last):
File "<stdin>", line 101, in <module>
File "<stdin>", line 68, in __init__
File "<stdin>", line 49, in read_uint8
IOError: [Errno 5] Input/output error
Here is some information about environment:
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l GNU/Linux
pi@raspberrypi:~ $ ls -a /dev/i2c*
/dev/i2c-1
pi@raspberrypi:~ $ cat /boot/config.txt | grep i2c
dtparam=i2c_arm=on,i2c_arm_baudrate=100000
dtoverlay=i2c-sensor
pi@raspberrypi:~ $ lsmod
Module Size Used by
bnep 10340 2
hci_uart 17943 1
btbcm 5929 1 hci_uart
bluetooth 326105 22 bnep,btbcm,hci_uart
brcmfmac 186403 0
brcmutil 5661 1 brcmfmac
cfg80211 428431 1 brcmfmac
rfkill 16037 4 cfg80211,bluetooth
snd_bcm2835 20447 0
snd_pcm 75762 1 snd_bcm2835
snd_timer 19288 1 snd_pcm
snd 51908 3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_wdt 3225 0
bcm2835_gpiomem 3040 0
uio_pdrv_genirq 3164 0
uio 8000 1 uio_pdrv_genirq
i2c_bcm2708 4834 0
i2c_dev 5859 0
fuse 84037 1
ipv6 347594 30
Summary: i2cdump reads all bytes from sensor, but reading via i2cget fails in most cases. The behaviour is random and inconsistent (in most cases it results in error).
I have also collected data about signals on wires using piscope. Here is a successful i2cget: i2cget -y 1 0x77 0xd0 - returns 0x55
And here is a failed byte read: i2cget -y 1 0x77 0xd0 - Error: Read failed
回答1:
Resolved. I had wrong connection on GND bus.
来源:https://stackoverflow.com/questions/41407261/read-byte-fails-on-raspberry-pi-3-errno-5-input-output-error