使用 Python 模块 SMBus、Raspberry Pi 和 Arduino 的输入/输出错误 [英] Input/output error using Python module SMBus, a Raspberry Pi and an Arduino

查看:25
本文介绍了使用 Python 模块 SMBus、Raspberry Pi 和 Arduino 的输入/输出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经连接了 Raspberry PiRainbowduino 以及自制的 I²C 电平转换器,以及安装了 Python 模块 SMBus,Raspberry Pi 可以与 Rainbowduino 通信,但在尝试命令 bus.write_i2c_block_data(address, signal, data) 时,我经常收到输入/输出错误消息.

I have connected a Raspberry Pi and Rainbowduino together with a homemade I²C level shifter, and installed the Python module SMBus, the Raspberry Pi can communicate with the Rainbowduino, but every so often I get an input/output error message when trying the command bus.write_i2c_block_data(address, signal, data).

它说:

IOError: [Errno 5] 输入/输出错误

IOError: [Errno 5] Input/output error

为什么会发生这种情况,我该如何修复或忽略这些错误?

Why does it happen and how do I fix or ignore these errors?

推荐答案

我正在创建一个带有 Raspberry Pi 和带有 i2c 的 Arduino UNO 的嗡嗡声服务器,但遇到了同样的问题.我的设计是,当 Pi 从套接字(由网络上的某些外部机器)接收到连接请求时,它会向 Arduino 写入1",Arduino 将通过更改全局变量来启用 loop() 中的循环.写入后 Pi 将不断从 Arduino 读取字节以检查按钮状态.当 Pi 想要停止读取时,它会发送0"以停止循环并重置所有计数器和 LED.

I am creating a buzzing server with a Raspberry Pi and Arduino UNO with i2c and has encountered the same problem. My design is that when the Pi receives a connection request from a socket(by some external machines on the network), it writes '1' to the Arduino and Arduino will enable a loop in loop() by changing a global variable. after the write Pi will continuously read byte from Arduino to check for button state. when the Pi wants to stop reading it sends '0' to stop the loop and reset all counters and LED.

发生的事情是 Python 在写入字节时会随机通过 IOError.在带有 Arduino 的串行监视器上,我注意到收到的最后一个字节是 1 而不是 0,这是 pi 应该发送的.在查看 i2cdetect -y 1 时,我注意到地址错误,我尝试了 Jon 的方法,但正如 user3126397 所提到的,错误数据已发送,Arduino 已停止.我尝试了他的 modprobe 并且只抑制了错误消息并且 Arduino 仍处于停止状态.

What happens is that Python will through IOError randomly when writing byte. On the Serial monitor with Arduino I noticed that the last byte received is 1 instead of 0, which is what the pi should have sent. Upon looking at i2cdetect -y 1 I noticed the address is wrong and I tried Jon's method, but as user3126397 mentioned, the bad data has been sent and the Arduino has halted. I attempted his modprobe and that only suppressed the error message and the Arduino is still in halt state.

我最初怀疑数据因为读/写不完整而变质,因此添加了一个 Serial.println() 来检查 onReceive() 中的参数 byteCount.在不改变任何其他代码的情况下,我观​​察到没有.IOError 之前成功操作的数量增加了很多.因此,我尝试添加更多 println() 来测试相关性,并注意到失败的急剧增加.最后,我评论了所有的 Serial 语句,最终我可以毫无故障地使用服务器很多次(我测试了大约 30 次,但仍然没有出现 IOError).

I originally suspect that the data gone sour because of incomplete read/write and therefore added a Serial.println() to check the argument byteCount in onReceive(). Without altering any other code I observed that the no. of successful operations before IOError increased a lot. Therefore I tried to add more println() to test the correlation and noticed a dramatic increase in failure. Finally I commented all the Serial statements and I ended up able to use the server without faults for a considerable number of times(I tested something like 30 times and still no IOError).

我怀疑,关于 user3126397 关于重置波特率的解决方案以及我对 Serial.println() 关系的观察,该错误确实是由 pi 和 Arduino 之间的同步问题引起的(因为 Serial 相对较慢并导致更多延迟在程序中,从而增加了失败的机会.

I suspect, with regard to user3126397's solution on resetting the baudrate and my observation on the Serial.println() relationship, that error is indeed caused by synchronisation issues between the pi and Arduino(as Serial is relatively slow and causes more delay in the program, thus increases the chance of failure.

这篇关于使用 Python 模块 SMBus、Raspberry Pi 和 Arduino 的输入/输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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