I am creating a robot that is remotely controlled using Python to send control messages over the Internet via a simple graphical interface.
I got a part of my code that works very well, a graphical interface and a control system, but I'm stuck. I am trying to use the ping parallax sensor to get the distance to object information from an Arduino Mega and send this value to my Python script control for display on the remote GUI.
The main problem I am facing is how to integrate Python code that will use the already installed COM port with Arduino, and send a message to tell Arduino to poll the ping sensor, and then send it to a Python program that will get the value and then let me paste this value into my GUI.
I already have this code to control the Arduino, and it works with my simple graphical interface.
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()
What I really would like to do is improve the code above and add a button to click to tell Python to send a message to Arduino to check the ping sensor and return the value. I am very knowledgeable with Arduino code, but I just started playing with Python in the last two weeks.
grinan barrett
source share