我有 adafruit 压力和温度传感器 BMP180 连接到 Raspberry Pi 3 的 I2C。在 I2C 的 0x77 地址上检测到该设备,i2cdump 运行没有错误并显示正确的值(例如,博世文档中描述的 0xD0 中的字节 0x55)。但是在大多数情况下读取一个字节会导致输入/输出错误。
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
在大多数情况下,从 Adafruit(用于 BMP180 传感器)执行示例也会返回错误:
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
我还编写了脚本来从这个传感器读取字节,使用 smbus2 或 smbus-cffi。结果是一样的:很少读取字节,在大多数情况下我得到错误:
➜ 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
以下是有关环境的一些信息:
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
摘要: i2cdump 从传感器读取所有字节,但在大多数情况下通过 i2cget 读取失败。行为是随机且不一致的(在大多数情况下会导致错误)。
我还使用 piscope 收集了有关电线上信号的数据。这是一个成功的 i2cget: i2cget -y 1 0x77 0xd0 - 返回 0x55
这是一个失败的字节读取: i2cget -y 1 0x77 0xd0 - 错误:读取失败