python - 'IOError : [Errno 5] Input/output error' while using SMBus for analog reading through RPi

标签 python python-2.7 raspberry-pi analog-digital-converter

我一直在寻找标题中提到的错误的答案,但我还是第一次得到答案。我们将尝试让我的 Raspberry pi 读取模拟数据,但是当我在终端窗口中运行代码时,它给了我“IOError:[Errno 5] Input/output error”。

我用来读取模拟数据的代码如下所示。我使用 PCF8591 ADC 转换器。

from smbus import SMBus

bus = SMBus(0)

print "read a/d press ctrl + c to stop"

bus.write_byte(0x48, 0)
lastval = -1

while True:
  reada = bus.read_byte(0x48)
  if(abs(lastval-reada) > 2):
    print(reada)
    lastval=reada

我知道这可能是因为树莓派中的版本发生了变化,我应该将 SMBus(0) 更改为 SMBus(1)。为此,我检查了我的 RPi 版本,它不是修订版。但是我仍然尝试通过更改 SMBus 号码来运行程序,但仍然没有成功。

我得到的错误如下所示:

Traceback (most recent call last):
  File "analogread.py", line 7, in <module>
    bus.write_byte(0x48, 0)
IOError: [Errno 5] Input/output error

感谢任何帮助。这是我试图执行的更大项目中的基本 block 。所以,我越瘦,我就越能构建我的应用程序。 谢谢

最佳答案

造成这种情况的原因可能是您正在远程工作 (SSH)。 断开远程 session 后,您的程序仍在工作,并且可以尝试打印或与控制台交互,这不再可用。这就是发生在我身上的事情。

关于python - 'IOError : [Errno 5] Input/output error' while using SMBus for analog reading through RPi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30325351/

相关文章:

python - 删除反斜杠继续字符

python - 基本的 Python 文件搜索和 I/O

python - 在AWS EKS中打印/返回python应用程序docker图像输出而不使用flask

php - Raspberry php不向arduino发送串行数据

java - ./run_timer.sh : no such file or directory

python - 无法在 Azure - web.config 上部署基本 Python 3.6?

python - Python 的机器人框架关键字 : Error with unmatched string or IP. 如何解决此问题?

python - 抓取 react-id

python - 在python中查找数组的转折点

assembly - ARM 组件 Raspberry-Pi : Converting a string to Upper case