问题描述
我在构建是使用Python通过一个简单的GUI通过互联网发送控制消息的远程控制的机器人的过程
I am in the process of building a robot that is remote controlled using Python to send control messages via the Internet through a simple GUI.
我已经得到我的code工作pretty的一部分很好,图形用户界面和控制系统,但我坚持。我试图用一个视差平传感器从到对象的信息的距离,该值发送给我的Python脚本控制要显示在远程GUI。
I have gotten part of my code working pretty well, the GUI and control systems, but I am stuck. I am trying to use a parallax ping sensor to get distance to objects information from an Arduino Mega, and send that value to my Python control script to be displayed on the remote GUI.
这是我遇到的主要问题是如何整合Python的code将使用已经建立的COM端口与Arduino的和发送消息,告诉Arduino的轮询平传感器,然后发送到一个Python程序将获得的价值,然后让我插入值到我的GUI。
The main problem that I am having is how to integrate Python code that will use the already established COM port with the Arduino and send a message to tell the Arduino to poll the ping sensor and then send to a Python program which will receive the value, and then let me insert that value into my GUI.
我已经有这个code控制Arduino的,和它的作品,我的简单的GUI。
I already have this code to control the Arduino, and it works, with my simple GUI.
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600)
from PythonCard import model
class MainWindow(model.Background):
def on_SpdBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
def on_FBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
ser.write('@')
ser.write('F')
ser.write(chr(spd))
def on_BBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
ser.write('@')
ser.write('B')
ser.write(chr(spd))
def on_LBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
ser.write('@')
ser.write('L')
ser.write(chr(spd))
def on_RBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
ser.write('@')
ser.write('R')
ser.write(chr(spd))
def on_SBtn_mouseClick(self, event):
spd = self.components.SpdSpin.value
ser.write('@')
ser.write('S')
ser.write('0')
def on_PngDisBtn_mouseClick(self, event):
ser.write('~')
ser.write('P1')
ser.write('p2')
app = model.Application(MainWindow)
app.MainLoop()
我真的很想做的是改进上述code和添加一个按钮点击来告诉Python将消息发送到Arduino检查平传感器和返回值。
我非常识字与Arduino的code,但我刚开始在过去两周与Python玩。
What I would really like to do is improve the above code and add a button to click to tell Python to send a message to the Arduino to check the ping sensor and return the value.I am very literate with the Arduino code, but I just started playing with Python in the last two weeks.
推荐答案
也许退房:
pyduino是一个库,它允许您使用装有从内部Python中Firmata协议的Arduino板通信。目前,它支持Firmata协议的版本2。
这篇关于如何从Arduino的送价值,Python和然后使用该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!