擅长:python、mysql、java
<p>好吧,一个朋友帮了我一把,我离得不远了。一旦我走到这一步,我只是一个IO错误的小问题。我遇到了[Errno 5]个IO错误。确保Arduino和Pi之间有接地。当我搜索的时候,这似乎被许多解决方案忽略了。你需要SDA,SLA和Gnd都连接起来。在</p>
<p>不管怎么说,这是运行arduino i2c闪烁草图的代码。根据I2C上Rpi输入的滑块,这将使引脚13上的led闪烁更快或更慢。我将尝试编写此代码来控制下一个伺服,如果成功,我也将发布该代码。在</p>
<p>Rpi/python2代码如下:</p>
<pre><code>from Tkinter import*
import RPi.GPIO as GPIO
import time
import smbus
bus = smbus.SMBus(1)
SLAVE_ADDRESS = 0x28
class App:
def __init__(self, master):
def SendScaleReading(self):
S = scale.get()
print("we have" );
print( S )
bus.write_byte_data(SLAVE_ADDRESS, S, S )
frame = Frame(master)
frame.pack()
scale = Scale(frame, from_=0, to=180, orient=HORIZONTAL, command=SendScaleReading)
scale.grid(row=1, column=1)
root = Tk()
root.wm_title('I2C servo control')
app = App(root)
root.geometry("200x50+0+0")
root.mainloop()
</code></pre>
<p>Arduino i2c导线闪烁示意图如下:</p>
^{pr2}$