使用Python模块的SMBus,树莓Pi和一个Arduino输入/输出错误 [英] Input/output error using Python module SMBus, a Raspberry Pi and an Arduino
问题描述
我连接了树莓派和<一个href=\"http://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems#Software-compatibility_only\">Rainbowduino用自制的I²C电平转换器,并安装的Python 模块的SMBus 的树莓派可以与沟通Rainbowduino,但每隔一段时间尝试命令时,我得到一个输入/输出错误信息 bus.write_i2c_block_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)
.
它说:
IO错误:[错误5]输入/输出错误
IOError: [Errno 5] Input/output error
它为什么会发生,如何修复或忽略这些错误?
Why does it happen and how do I fix or ignore these errors?
推荐答案
人长话短说很多受此困扰,我发现了一个很简单的解决方法是如下。
Long story short alot of people are plagued by this, I found a very simple work around is the following.
它可以让你忽略错误并保持TX / RX-ING,呼吁i2cdetect似乎重新初始化总线,而不是莫名其妙Arduino的从中消失。
It will let you ignore the error and keep tx/rx-ing, calling i2cdetect seems to reinitialize the bus somehow instead of the arduino disappearing from it.
我张贴的我怎么会在这里发现了这个解决方案的解释(目前等待审批MOD)
http://www.raspberrypi.org/phpBB3/viewtopic.php ?F = 41&amp; T公司= 52517
i posted an explanation of how i found this solution here (waiting mod approval right now) http://www.raspberrypi.org/phpBB3/viewtopic.php?f=41&t=52517
try:
bus.write_i2c_block_data(address, signal, data)
except IOError:
subprocess.call(['i2cdetect', '-y', '1'])
flag = 1 #optional flag to signal your code to resend or something
尽管这允许pi到保持发送坏数据仍被发送到Arduino。我发现来解决这个问题,最简单的方法是一个额外的校验和字节添加到我的数据块的结束。
Even though this allows the Pi to keep transmitting bad data is still being sent to the arduino. The simplest way I found to get around this was to add an extra check-sum byte to the end of my data blocks.
我添加了消息的每个字节一个字节变量中允许值侧翻,那么校验和字节分配任何必要来总结整个消息超时值为零。
I added up each byte of the message inside a byte variable allowing the value to rollover, then assign the check-sum byte whatever value necessary to sum the whole message out to zero.
Arduino的然后可以通过所有字节求和检查每个输入的传输。如果消息不总结出来为零,则忽视的一个错误传输。
The arduino can then check each incoming transmission by summing all the bytes. If the message does not sum out to zero, it is ignored as an erroneous transmission.
我也分到我的消息,这些消息每次成功发送后递增,消除双重意外的可能性发送一个字节的消息ID。但事实可能并非真的是必要的。
I also assigned my messages a one byte message id which increments after each successful transmission, eliminating the possibility of accidental double sends. But that may not really be necessary.
这篇关于使用Python模块的SMBus,树莓Pi和一个Arduino输入/输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!