在Raspberry Pi 3上读取字节失败:[errno 5]输入/输出错误 [英] Read byte fails on Raspberry Pi 3: [errno 5] input/output error

查看:210
本文介绍了在Raspberry Pi 3上读取字节失败:[errno 5]输入/输出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将adafruit压力和温度传感器BMP180连接到Raspberry Pi 3的I2C.在I2C的0x77地址上检测到该设备,i2cdump运行无错误并显示正确的值(例如,如博世文档中所述,0xD0中的字节0x55) .但是在大多数情况下,读取字节会导致输入/输出错误.

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

在大多数情况下,从Adafruit(对于BMP180传感器)执行示例也会返回错误:

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

我还编写了脚本,使用smbus2或smbus-cffi从此传感器读取字节.结果是一样的:很少读取字节,在大多数情况下,我会出错:

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 

摘要: i2cdump会从传感器读取所有字节,但是在大多数情况下,通过i2cget读取会失败.该行为是随机的和不一致的(在大多数情况下,它会导致错误).

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).

我还使用piscope收集了有关电线上信号的数据. 这是一个成功的i2cget: i2cget -y 1 0x77 0xd0-返回0x55

I have also collected data about signals on wires using piscope. Here is a successful i2cget: i2cget -y 1 0x77 0xd0 - returns 0x55

这是一个失败的字节读取: i2cget -y 1 0x77 0xd0-错误:读取失败

And here is a failed byte read: i2cget -y 1 0x77 0xd0 - Error: Read failed

推荐答案

已解决. 我在GND总线上的连接错误.

Resolved. I had wrong connection on GND bus.

这篇关于在Raspberry Pi 3上读取字节失败:[errno 5]输入/输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆